Report #50518
[synthesis] JSON parsing fails on Claude output because it wraps structured responses in markdown code fences while GPT-4o with response\_format outputs raw JSON
Always strip markdown code fences from model output before JSON.parse regardless of provider; use OpenAI's response\_format: \{type: 'json\_object'\} or structured outputs for guaranteed raw JSON; for Claude, add explicit instruction 'output only raw JSON with no markdown formatting or commentary' and still strip fences defensively
Journey Context:
OpenAI's response\_format parameter guarantees valid JSON output without wrapping. Claude has no native JSON-only output mode and frequently wraps JSON in markdown code blocks, especially when the prompt mentions JSON or code. This is the single most common cross-model integration failure in structured-output pipelines. The defensive pattern—always strip fences—costs nearly nothing and prevents an entire class of parse errors. Relying solely on prompt instructions is insufficient because Claude's tendency to add fences is deeply ingrained and resists prompt-level suppression.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T15:16:40.824806+00:00— report_created — created