AI models are surprisingly good at writing Mermaid. Describe what you want in plain English and MermaidViewer's AI diagram generator produces valid Mermaid code that renders instantly — then you can refine it by hand or with more instructions.
The anatomy of a good prompt
- Diagram type — "a sequence diagram", "an ER diagram". If you don't specify, the AI picks the most suitable type.
- Actors or entities — who or what appears in the diagram.
- Steps and branches — the happy path plus important alternatives and errors.
- Constraints — direction (left to right), level of detail, labels to include.
Prompt examples
| Goal | Prompt |
|---|---|
| Flowchart | Flowchart, left to right, of our refund process: request, eligibility check, manager approval for amounts over $500, refund, email confirmation. |
| Sequence | Sequence diagram of a mobile app logging in with Google via our backend, including token refresh. |
| ER | ER diagram for a gym: members, memberships, classes, trainers, bookings, with keys. |
| Gantt | Gantt chart for a 6-week website redesign starting March 2, 2026, excluding weekends. |
Four AI actions in the editor
- Generate — create a new diagram from a description.
- Edit — change the current diagram with an instruction such as "add a caching layer" or "translate labels to Spanish".
- Fix — repair syntax errors using the parser's error message.
- Explain — get a plain-English explanation of a diagram, useful for reviews and accessibility.
Convert existing content
You can paste source material — SQL CREATE TABLE statements, a list of API endpoints, meeting notes or a bullet outline — and ask for the matching diagram type. This is the fastest way to document an existing system.
Everyone gets 5 free AI uses in total (counted per account and per IP). Starter includes 500 AI conversations a month and Pro is unlimited, so save the free ones for big first drafts.
Prompt patterns
The four buttons are already listed above. What changes the diagram is the wording. These mermaid ai prompts are patterns you can reuse, pointed at the AI diagram generator.
Pattern A is a spec, not a vibe. Name the type, the direction, the actors, the happy path, one failure, and what to leave out. "Flowchart, top down" is a different request from "diagram". Leaving out the refund path is a requirement. If you don't say it, the model may add one.
Pattern B is an exact vocabulary list. Paste the service names as a bullet list and add "use these labels and no others." Models rename Shop API to Backend because Backend sounds cleaner. Your on-call docs don't say Backend.
Pattern C is a revision that protects the previous draft. "Keep every node id. Add a failure edge from Pay to Retry. Do not add services. Do not restyle." A revision that says "make it better" spends a use and shuffles labels you already fixed.
Pattern D is a source dump with a mapping rule. SQL, bullets, or a list of endpoints goes in the prompt, followed by the diagram type and the rules for keys, arrows, or decisions. The next two sections are that pattern in full.
Write the prompt in the order the model should commit: type, names, sequence, exceptions, exclusions. An exclusion buried at the end is easy for the model to treat as a suggestion. Put "do not add a cache" in the same sentence as the path it would attach to.
A sequence prompt needs the return trip, or you get a one-way chart. "Sequence diagram. Participants: App, API, DB. App calls API with POST /login. API reads DB. DB returns a row. API returns 200 to App. If the row is missing, API returns 401 and does not create a session." Name the reply. Models draw the request and forget the dashed line home. The sequence tutorial is where you add numbering and notes after the draft is honest.
A weak prompt and a tighter one
Weak prompt: "Make a diagram of our checkout."
That sentence doesn't name a type, a system, a failure, or a limit. The draft will be plausible and wrong. It might be a sequence diagram when you wanted a flowchart. It might invent a fraud service. You then spend more uses undoing fiction.
Tighter prompt: "Flowchart, top down. Nodes only: Cart, Pay, 3-D Secure, Ledger, Receipt. Decision on Pay: card accepted? If yes, write the Ledger and show the Receipt. If no, show a retry, and after two retries stop. Label the edges yes and no. Do not add a refund, a queue, or a service that is not in the node list."
The diagram that prompt is asking for looks like this. If the generator returns extra nodes, delete them. Don't ask for a third draft to remove a box you can erase in one line.
flowchart TD
Cart --> Pay{Card accepted?}
Pay -->|Yes| Secure[3-D Secure]
Secure --> Ledger[(Ledger)]
Ledger --> Receipt
Pay -->|No| Retry[Retry]
Retry --> PayRead the draft against the prompt before you read it as a picture. Is 3-D Secure on the yes path, where you put it? The sample above places it after acceptance. If your real flow challenges the card before you know it was accepted, the prompt was wrong, not the tool. Fix the sentence and generate once more, or edit the arrow by hand if that is the only change.
A tighter prompt is longer. Length is not the goal. Constraints are. A long prompt that still says "and anything else relevant" invites the invented box back.
Paste SQL or a bullet list
SQL belongs in the prompt as the schema, with rules after it. Open Generate, paste the statements, and tell the model what kind of picture you want.
CREATE TABLE students (
id INT PRIMARY KEY,
email TEXT UNIQUE,
name TEXT NOT NULL
);
CREATE TABLE courses (
id INT PRIMARY KEY,
title TEXT NOT NULL
);
CREATE TABLE enrollments (
student_id INT REFERENCES students(id),
course_id INT REFERENCES courses(id),
enrolled_on DATE,
PRIMARY KEY (student_id, course_id)
);The instruction under the SQL: "Turn this into a Mermaid erDiagram. One entity per table. Mark primary keys PK and foreign keys FK. Enrollment is a join table: one-to-many from students and from courses. Skip nothing in this snippet, and do not add audit columns." That last clause matters. Models love created_at. You didn't ask for it, and it clutters the ER diagram. The SQL to Mermaid guide is the checklist you use to review the draft: cardinality, nullable keys, and whether the line is identifying.
Bullet notes work the same way for a process. Paste the notes you already have. Don't rewrite them into prose first.
- Student submits the form
- Registrar checks the prerequisite
- If the prerequisite is missing, reject with the course name
- If it is met, write the enrollment
- Email the studentThe instruction: "Flowchart, top down, one node per bullet. The prerequisite check is a diamond. Edges labeled met and missing. Use the words in the bullets as labels. Do not merge the email into the write step." Merging is the model's favorite shortcut. Forbidding it keeps a step you will need when email fails and the row is already written.
For either dump, say what to do with uncertainty. "If a foreign key is missing, leave the relationship out rather than guessing a link." A guessed arrow parses. It is still a defect. You would rather see a hole.
Review a SQL draft with the schema beside it. Every REFERENCES should be one line in the diagram. Every primary key in the SQL should be marked PK. A join table should show two one-to-many relationships, not a single many-to-many line that hides the table you actually have. If the model drew STUDENT }o--o{ COURSE and dropped ENROLLMENT, it simplified the schema. Your prompt asked it not to. Put the entity back by hand or generate once with the sentence "keep the enrollments table as its own entity."
Bullet drafts fail in a smaller way. The model merges two bullets or turns a statement into a diamond. Count nodes against bullets before you admire the layout. Five bullets, five nodes, plus the diamond only if a bullet was a question. Extra nodes are inventions. Missing nodes are merged steps. Both are edits you can do without another use.
When to stop and edit by hand
Stop when the diagram parses and the labels match your list. The next prompt is where renames creep in. Move a node, change a direction, add a quote around a label, or wrap a subgraph in the editor. Those are one-line edits. Spending a use on "make the layout nicer" asks a text model to do a layout engine's job. Mermaid places the shapes. Change TD to LR, or add a subgraph, yourself. The flowchart guide shows both.
Stop when the model invents a participant. Delete the node and the edges. A follow-up prompt often invents a different extra. Your hand edit is stable.
Stop when the syntax is valid and the story is wrong. Another generation will produce a different wrong story with equal confidence. Rewrite the prompt from the notes, or fix the edge. Look at retries in the checkout sample. If your policy allows one retry, change the label. Don't ask the model to "handle retries properly."
Stop when you are styling. Colors, fonts, and classDef are the themes guide. The generator will burn a use on a fill you can type.
Two revisions that still miss the structure means the prompt is missing a fact. Go back to the SQL or the bullets. Add the fact. Generate from that, rather than stacking "no, I meant..." messages that the model half-remembers.
Hand edits to keep: exact table names, exact HTTP paths, cardinalities you verified, and any label with punctuation you already quoted. Hand edits to throw away: a clever abbreviation only you understand. The next reader is the reason the label exists.
How many uses you get
The free tier is 5 AI uses in total, not 5 a day and not a refill. The number that applies is the highest of three counters: your account, a hash of your IP address, and a device cookie. A new account on the same network does not reset the pool. Spend the five on first drafts of diagrams you will keep, not on color tweaks.
Starter is $6.99 a month and includes 500 AI uses a month. That is enough for a team that generates a draft and revises it a few times a week. Pro is $11.99 a month and is unlimited for normal use, with a fair-use cap so a script can't drain the service. Neither plan makes a vague prompt accurate. They only change how many drafts you can afford.
Each call to the model counts, whether you generate, edit, fix, or explain. Fixing a quote by hand is free. Previewing in the editor is free. Downloading a file doesn't consume an AI use. Every plan can download a PNG: 1× with a watermark on Free, up to 4× on Starter, up to 8× on Pro. JPG, SVG, and PDF are on Pro. If you are down to your last free use, paste the tight prompt, not the sentence "make a diagram of our checkout."
Keep a scratch file of prompts that worked, next to the diagram. The next chart in the same system should start from that prompt with the names swapped, not from a blank box. You already paid for the constraints. Reusing them is how five uses cover more than five diagrams.
A prompt that survives a second try, and why five free uses go fast, is prompt to mermaid diagram.