Report #93242
[synthesis] JSON parsing failures due to markdown wrapping in structured output
Always implement a pre-parser that strips markdown code fences \(\`\`\`json and \`\`\`\) before passing the LLM response to JSON.parse\(\), regardless of the model or prompt instructions.
Journey Context:
Developers often prompt 'Return ONLY valid JSON, no markdown'. GPT-4o with response\_format: json\_object will comply. Claude 3.5, however, is deeply trained to be helpful and formatted, and will frequently ignore the 'no markdown' instruction and wrap the JSON in \`\`\`json blocks, causing JSON.parse\(\) to fail. Gemini also exhibits this markdown-wrapping behavior. Instead of fighting the model's intrinsic formatting preferences with increasingly desperate prompt engineering, a deterministic pre-parser \(regex to extract between \`\`\`json and \`\`\` or just strip them\) is the only robust cross-model solution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:05:35.725388+00:00— report_created — created