Guide

Fix Mermaid diagrams generated by ChatGPT

Chatbots write Mermaid that looks right and fails with “Parse error on line 3”. The mistakes are almost always the same handful. Here they are, with the exact message Mermaid prints for each, so you can recognise them at a glance.

Updated

After the fixes: the same diagram, rendered Edit and export
flowchart TD
  A["User opens app (mobile)"] --> B{Logged in?}
  B -->|Yes| C["Show “Home”"]
  B -->|No| D[Login page]
  D --> E[Submit form]
  E --> End

A typical broken answer

Five errors in seven lines
```mermaid
flowchart TD
  A[User opens app (mobile)] --> B{Logged in?}
  B -->|Yes| C[Show "Home"]
  B -->|No| D[Login page]
  D -> E[Submit form]
  E --> end
```
  1. The Markdown fence (the lines with three backticks) was copied too. It belongs to Markdown; a Mermaid editor sees it as text.
  2. (mobile) inside […]: parentheses start a round shape, so the label breaks.
  3. "Home" inside […]: straight double quotes inside an unquoted label.
  4. -> has one dash; flowchart links need two (-->).
  5. end is a keyword (it closes subgraphs), not a node name.

The corrected version is drawn above. The Mermaid syntax checker opens with this exact sample and fixes all five in one click.

Error messages decoded

Look at the word after got at the end of the message. These are the messages printed by the Mermaid version Arrowly ships for each mistake.

Message ends withUsual causeFix
got 'PS'( inside a label in […], (…) or |…|Quote the label: A["Call (v2)"]
got 'STR'Double quotes inside an unquoted labelQuote the whole label and use “curly” quotes inside
got 'end'A node called endRename it End or done
got 'MINUS'-> in a flowchart-->
got 'NODE_STRING'Space inside a node id (my node --> B)myNode[My node] --> B
got '1'The parser reached the end: unclosed bracket or a subgraph without endClose the bracket, add the end
Expecting 'TXT', got 'NEWLINE'Sequence message without a colonA->>B: text
... got 'NEWLINE' on a sequence line with ;Semicolon inside a messageReplace it with a comma
Lexical error ... Unrecognized textA character Mermaid doesn't read there, often →--> (flowchart) or ->> (sequence)
No diagram type detectedFence lines or no flowchart/sequenceDiagram on topRemove the fence, add the type
No such shape: …Invented name in @{ shape: … }Use a name from the shapes list

Ask the chatbot for code that parses

If you keep generating diagrams in a chat, add these constraints to your prompt. They remove most of the errors above at the source.

Prompt add-on
Write Mermaid flowchart syntax only, without a Markdown fence. Put every node label in double quotes: A["Label"]. Use --> for links, never ->. Node ids are single words in camelCase; never use end as an id. No parentheses, quotes or semicolons outside quoted labels.

Arrowly avoids the problem differently: its AI never writes Mermaid. It returns the boxes and arrows as data, and Arrowly writes the code from that, escaping every label, so the result always parses.

Skip the broken code entirely

Paste the notes you were going to give the chatbot. Arrowly draws the diagram and writes Mermaid that always parses, with a live editor and SVG/PNG export. 3 free diagrams a day, no signup.

Draw from my notes

Questions

Why does the same code work in ChatGPT's preview but not in my docs?

Different Mermaid versions. Newer versions accept syntax older ones reject (and occasionally the reverse). Check which version your docs tool runs, and prefer the classic syntax for portability.

Is it safe to paste internal diagrams into the checker?

Yes. The checker parses and draws in your browser; the code is not uploaded.