Validate D2 Code
d2_validateCatch syntax and semantic errors in D2 source code before rendering. Returns structured valid/error result using WASM, with no d2 binary required.
Instructions
Validate D2 diagram source code for syntax and semantic errors using the WASM engine.
Uses compile step to detect all errors without rendering. No d2 binary required.
Args:
d2_code (string): D2 source code to validate
Returns: JSON object: { "valid": boolean, // Whether the code is syntactically and semantically valid "error": string // Error message if invalid (omitted if valid) }
Examples:
Check before rendering: validate first, then d2_render only if valid=true
Debug syntax: get specific line/column error info
Error Handling:
Returns { valid: false, error: "..." } with specific error details
Never throws — always returns a structured result
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| d2_code | Yes | The D2 diagram source code to validate |