PlantUML with AI — prompt patterns for Copilot / Cursor auto-generation
In 2025-2026, LLMs can already convert a 5-sentence description into PlantUML code. This post distils the prompt templates, common errors, debugging tricks, and human-review rules I’ve tested.
LLMs writing PlantUML today (mid-2026)
Empirically:
- Copilot / Cursor / Cline: with
.pumlfile context, 5-10 line prompts reach ~80% correct code - ChatGPT / Claude / Gemini: system prompt + detailed description → working code in 5-15 seconds
- Key gap: the UML semantics LLM handles; the visual layout (node position, spacing, colour) it gets wrong constantly — needs human review
Making LLMs output correct PlantUML
1. Constrain the output format
LLMs struggle to self-constrain output. Force the boundary in your prompt:
1 | Output ONLY the PlantUML code block, no explanation outside the block. |
Otherwise you’ll get:
1 | ```plantuml |
followed by “Here is the PlantUML code…” commentary. You want pure content.
2. Lock the diagram type
PlantUML has 20+ diagram types — LLMs often guess wrong:
1 | Draw a UML sequence diagram in PlantUML with EXACTLY these participants: |
Force “EXACTLY these participants” + order + relation type + “no skinparam”.
3. Provide examples (few-shot)
The fastest way for an LLM to learn is via examples. Give one in the same conversation; later prompts will use the template:
1 | Use this as a reference structure (don't copy verbatim): |
4 Carry context across turns: first turn defines “sequence-diagram rules”. Second turn says “draw X in the same format”. Third turn says “draw another X” — the LLM applies the prior template.
Practical prompt templates
Template 1: sequence diagram
1 | # Task |
Template 2: class diagram
1 | # Task |
Template 3: activity diagram
1 | Convert this flow description into a PlantUML activity diagram: |
Template 4: state machine
1 | Convert this state enum into a PlantUML state diagram: |
Common LLM errors (you must know these)
Error 1: arrow direction nonsense
1 | @startuml |
LLM training data mixes old PlantUML with Mermaid arrow styles. Reverse arrows are not a thing in PlantUML. Catch these in review and rewrite as Bob -> Alice.
Error 2: wrong composition/aggregation
1 | User *-- Role ' user "owns" role (composition) |
Sometimes the LLM writes User -- Profile when it meant composition. Watch --* vs --o: composition uses solid diamond *, weak ownership uses hollow o.
Error 3: bracket / end mismatch
1 | package "Frontend" { |
LLMs often miss a closing brace, end, endif. Always recount.
Error 4: message text containing :
1 | Alice -> Bob: prefix:value ' ❌ colon breaks the message |
LLMs happily paste JSON-style key:value into message text. Always review with quoted message text.
Error 5: gratuitous skinparam
LLMs often emit:
1 | skinparam backgroundcolor #fafafa |
Results are visually ugly. Disable in the prompt: “Use no skinparam customization.”
Error 6: hallucinated !include paths
LLMs write:
1 | !include ./common/styles.puml |
These paths may not exist in your repo. Never render LLM-generated !include directly — confirm paths exist and copy files first.
Verification workflow
1. Local PlantUML CLI smoke test
1 | echo "@startuml |
If PlantUML errors (YAMLException / $jsException / no dot found), fix source first.
2. Look at it in VS Code
VS Code PlantUML plugin shows the rendering. If you see:
- overlapping nodes → adjust
nodesepor addpackage - edges crossing nodes → bump
ranksepor splitpackage - weak arrow colour → add
skinparam ArrowColor #5B7C99
3. View in the final docs page
The deliverable is the docs page — always check visuals at the final destination (Hexo / GitHub / Notion).
Copilot auto-complete template
In VS Code + Copilot, drop a .copilot-instructions.md at the repo root so it auto-follows PlantUML rules:
1 | When generating PlantUML code (between @startuml and @enduml): |
Place at repo root → Copilot adopts automatically in .puml files.
Cursor / Cline usage
These two are more agentic — say:
“Add an error-handling branch to docs/diagrams/auth-flow.puml”
The agent will:
- read existing auth-flow.puml
- execute PlantUML CLI render → view
- modify code → re-render → compare
- write to docs/diagrams/
Success rate 70-80% empirically — 2 out of 10 steps require the agent itself to debug, but still faster than hand-writing.
Six-axis checklist for LLM-generated diagrams
| Axis | How to test | Expectation |
|---|---|---|
| Syntax | PlantUML CLI renders without error | Required 100% |
| Semantics | Does the diagram express the business relation right? | Required 100% |
| Layout | Nodes don’t overlap, edges don’t cross others | Required ≥85% |
| Style | Not over-coloured / not flashy | 80% restrained |
| Readability | ≤8 nodes “read at a glance” | Big diagrams must be split |
| Maintainability | Adding a node touches ≤1 place | Low edit cost |
Recap
- LLMs writing PlantUML is “usable” today, but “perfect” still requires human review.
- Prompt keys: explicit diagram type + listing participants + listing messages + disabling styling.
- Error hotspots: arrow direction, composition relations, CJK,
:in message text. - Always validate via PlantUML CLI — don’t trust the LLM’s “should be correct”.
Next
- Title: PlantUML with AI — prompt patterns for Copilot / Cursor auto-generation
- Author: puml.online
- Created at : 2026-07-30 10:31:00
- Updated at : 2026-08-14 21:34:29
- Link: https://puml.online/blog/plantuml-ai-generation-en/
- License: This work is licensed under CC BY-NC-SA 4.0.