Here are some effective strategies for getting LLMs to output correct Mermaid syntax and be mindful of graph size:
- Explicit Syntax Guidance
When creating Mermaid diagrams, please:
- Use precise Mermaid syntax
- Ensure each line follows correct Mermaid formatting
- Validate the diagram structure before outputting
- Keep the diagram concise and readable
- Size and Complexity Constraints
Please follow these guidelines for Mermaid diagrams:
- Limit the diagram to 10-15 nodes maximum
- Avoid overly complex nested structures
- Prioritize clarity over exhaustive detail
- If the diagram becomes too large, suggest breaking it into multiple smaller diagrams
- Prompt Template Example
Create a Mermaid diagram with the following requirements:
- Use correct Mermaid syntax
- Validate each line of the diagram
- Keep the total number of nodes under 15
- Ensure readability and simplicity
- If the diagram exceeds recommended complexity, propose a simplified version
Diagram instructions: [Your specific diagram requirements]
- Demonstration and Examples
- Provide a correct Mermaid syntax example in your initial prompt
- Show both a good and a bad example to illustrate expectations
- Highlight specific syntax rules
- Iterative Refinement
- If the first output isn't correct, provide specific feedback
- Ask the LLM to review and correct its own syntax
- Request step-by-step explanation of the Mermaid diagram construction
Example Prompt:
Create a flowchart Mermaid diagram showing a simple decision process.
Strictly follow these Mermaid syntax rules:
- Use `graph TD` for top-down flow
- Use clear, concise node descriptions
- Limit to 5-7 nodes
- Use appropriate connection arrows
Validate your syntax before presenting the diagram.
By combining these strategies, you'll increase the likelihood of getting correct, concise Mermaid diagrams from LLMs.