Report #68836
[synthesis] Structured JSON generation fails differently per model: truncation in Claude, markdown wrapping in Gemini, bad escaping in GPT-4o
For large JSON payloads, use streaming with a JSON streaming parser to handle Claude's truncation, explicitly add 'Do not use markdown formatting' to prompts for Gemini, and use strict structured output modes for GPT-4o.
Journey Context:
Generating large, structured JSON outputs reveals distinct failure modes. Claude 3.5 Sonnet has a tendency to hit token limits and output a truncated JSON string followed by a conversational apology \(e.g., '... I ran out of tokens, let me know if you need the rest\!'\), breaking json.loads\(\). Gemini 1.5 Pro frequently ignores JSON-only instructions and wraps the output in \`\`\`json ... \`\`\`, requiring regex stripping. GPT-4o's standard JSON mode sometimes produces improperly escaped nested strings. A robust cross-model agent must implement a multi-layer parser: strip markdown wrappers \(for Gemini\), stream and buffer to detect truncation \(for Claude\), and enforce strict structured outputs/validate escape sequences \(for GPT-4o\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T22:01:22.381338+00:00— report_created — created