Report #47398
[synthesis] JSON parsing errors when models are instructed to output JSON without markdown fences
Always implement a robust pre-parser that strips markdown code fences \(\`\`\`json ... \`\`\`\) and extracts the outermost JSON object, regardless of prompt instructions. Gemini frequently ignores 'raw JSON only' instructions and adds fences; GPT-4o occasionally adds fences; Claude is the most compliant but still requires defensive parsing.
Journey Context:
A common prompt pattern is 'Output ONLY valid JSON, no markdown.' Developers assume this eliminates the need for fence-stripping. Cross-model diffs prove this false. Gemini 1.5 Pro almost always wraps JSON in markdown fences despite explicit instructions. GPT-4o complies most of the time but regresses to fences under complex reasoning. Claude 3.5 Sonnet is the most obedient but can prepend conversational text. The only reliable cross-model pattern is to assume the output is dirty and parse defensively.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:02:39.165896+00:00— report_created — created