Skip to content
Limited Time 40% off for early adopters — Get discount →

Diagram Validation

Last updated:

Mermaid Studio provides instant validation as you type, highlighting errors at their exact locations and detecting a variety of issues that Mermaid.js alone cannot catch.

Robust Syntax Error Detection and Reporting

Section titled “Robust Syntax Error Detection and Reporting”

Mermaid.js stops at the first syntax error it encounters, often with a generic message that doesn’t pinpoint the problem. Mermaid Studio uses proprietary parsers built specifically for IDE analysis and use them to analyze your entire diagram and report all errors at their exact locations.

Multiple errors detected

This means you can fix several issues in one pass rather than discovering them one at a time through repeated render attempts.

Beyond syntax errors, Mermaid Studio includes over 100 inspections that detect logical issues, deprecated syntax, and common mistakes. Inspections appear as warnings or hints in the editor without blocking diagram rendering.

Detects outdated syntax patterns and offers quick fixes to modernize your diagrams.

For example, Mermaid’s init directive (%%{init: ...}%%) is deprecated in favor of YAML frontmatter. Mermaid Studio flags this and provides a quick fix to convert automatically.

Convert init directive to YAML frontmatter

Flags references to elements that don’t exist, such as:

  • CSS classes used but never defined
  • Icons not found in enabled icon sets
  • Entity, class, or state names that don’t match any declaration

Quick fixes can often create missing definitions for you.

Unresolved reference

Warns when you define the same element twice, which can cause unexpected merge behavior or render failures.

Identifies CSS classes, entities, or other elements that are defined but never referenced. These may indicate leftover code that can be removed or missing references that should be added.

Detects content that will be silently modified or stripped by Mermaid’s rendering pipeline:

  • Unclosed HTML-like tags (e.g., <My Chart) in text content that DOMPurify will strip, causing unexpected content loss
  • Unsupported Unicode characters that certain diagram types cannot render

Catches semantic issues that are syntactically valid but logically problematic:

  • Circular dependencies in Gantt task scheduling
  • Invalid temporal order where a task’s start date falls after its end date
  • Unreachable states with no incoming transitions
  • Dead-end states with no outgoing transitions and not marked as final
  • Invalid lifecycle operations like deactivating an inactive participant in sequence diagrams

Issues like these can lead to unpredictable rendering output or even outright failure, so catching them early helps ensure your diagrams behave as expected. When Mermaid.js does catch these problems, it typically reports them as a generic render failure without pointing to a specific line. Mermaid Studio traces many of them back to the exact lines responsible.

Many inspections include quick fixes that resolve issues automatically. Place your cursor on a warning and press Option + Enter Alt + Enter to see available fixes.

Quick fix menu

Examples of quick fixes:

  • Convert to YAML frontmatter for deprecated init directives
  • Create CSS class definition for unresolved class references
  • Remove redundant statement for invalid lifecycle operations

Mermaid.js Parser Diagnostics Experimental

Section titled “Mermaid.js Parser Diagnostics ”

In addition to Mermaid Studio’s built-in validation, you can optionally surface errors from the Mermaid.js renderer directly in your editor. When enabled, this inspection captures parser errors reported by the live preview and highlights them inline, letting you see Mermaid.js errors without checking the preview panel.

This is useful for catching issues that Mermaid.js reports but that Mermaid Studio’s built-in parsers may not yet cover.

Mermaid.js parser diagnostics are disabled by default. To enable them:

  1. Go to Settings > Editor > Inspections
  2. Navigate to Mermaid > General
  3. Enable Mermaid.js parser diagnostics

Mermaid.js parser diagnostics inspection

The inspection requires the live preview to be open, since diagnostics are collected from the Mermaid.js renderer running in the preview panel. It works for both .mmd files and Mermaid code blocks in Markdown files.

Mermaid.js error messages often include imprecise or missing location information. Rather than displaying the raw position reported by the parser, Mermaid Studio uses heuristics to map each diagnostic to a more accurate location in your source code. The result is usually close, but may occasionally highlight a slightly different range than where the actual problem is.

When both Mermaid Studio’s built-in validation and Mermaid.js report an error at the same location, the Mermaid.js diagnostic is automatically suppressed to avoid duplicate error markers. This keeps the editor clean while still surfacing errors that only Mermaid.js detects.

Two registry keys provide additional control over the diagnostics pipeline. Access the registry via Help > Find Action ( Command + Shift + A Control + Shift + A ) and search for “Registry”.

KeyDefaultDescription
ms.preview.parser.error.diagnostics.enabledtrueControls whether the preview collects and stores parser diagnostics. When false, no diagnostics are collected regardless of the inspection’s enabled state.
ms.preview.parser.error.overlap.suppression.enabledtrueControls whether Mermaid.js diagnostics that overlap with existing error highlights are suppressed.

Errors and warnings appear as underlines in the editor. Hover over an issue to see a description of the problem.

To see all issues at once, open View > Tool Windows > Problems. Click any entry to jump directly to its location.

Validation works in Mermaid code blocks inside Markdown files, giving you the same error detection and inspections regardless of where you write your diagrams.