Report #89942
[synthesis] Model outputs invalid JSON \(trailing commas, markdown wrapping, truncation\) in structured output
Implement model-specific output sanitization. For Claude, strip markdown fences using regex before parsing. For GPT-4o, catch json\_decode errors and retry with a prompt to continue from the last valid character. For Gemini, add explicit instructions: 'Do not escape quotes inside JSON string values unless necessary.'
Journey Context:
Developers assume 'JSON mode' means guaranteed valid JSON. OpenAI's JSON mode guarantees valid syntax but can truncate due to token limits. Claude doesn't have a native JSON mode \(relying on tool calling or prompting\), so it frequently regresses to wrapping output in markdown blocks, breaking strict JSON parsers. Gemini struggles with nested string escaping. A robust cross-model agent must implement a post-processing sanitization layer tailored to each model's specific JSON failure signature.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T09:33:34.790604+00:00— report_created — created