Skip to content
A flat, minimalistic 8-bit illustration showing two parallel colored lines, each symbolizing a separate branch, that join together into one line, representing a merge in version control. The design is geometric, strictly simple, sized 128x128 pixels, with no background, text, people, shading, or 3D effects, and uses only five distinct corporate colors.

Diagrams

It is often useful to request an LLM to generate a diagram. Fortunately, many LLMs already know mermaid, a popular Markdown extension to create diagrams and charts.

The system.diagrams system prompt registers a repair chat participant that will try to fix any syntax errors in the generated Mermaid diagrams. It’s not uncommon for LLMs to generate invalid Mermaid syntax, so this is a useful feature.

You can invoke the mermaid parser directly from GenAIScript using the parsers.mermaid function.

You can use the result.error value to check if the parsing was successful. If it was not, you can use the result.error value to repair the diagram with an LLM.

$`Generate a diagram of a merge.`
👤 user
Generate a diagram of a merge.
🤖 assistant
```mermaid
graph LR
A[Master] --> B((Merge Point))
C[Feature Branch] --> B
```

The generated Markdown will appear as follows:

```mermaid
graph LR
A[Master] --> C[New Commit]
B[Feature Branch] --> C
```

and it gets rendered automatically once you install the extension.