Report #55841
[synthesis] Structured JSON output requests return markdown-wrapped JSON in some models but raw JSON in others, breaking downstream parsers
Implement a universal JSON extraction pre-parser that strips markdown code fences \(\`\`\`json...\`\`\`\) and surrounding text before JSON.parse. Add 'Output ONLY raw JSON with no markdown formatting, no code fences, no commentary before or after' to system prompts for all models, but do not rely on this alone — the extraction layer is mandatory.
Journey Context:
GPT-4o and GPT-4-turbo have a deeply ingrained tendency to wrap JSON in markdown code fences even when explicitly told not to. Claude models are more likely to output raw JSON when asked, but occasionally add a brief text preamble. Gemini models sometimes add explanatory text before or after the JSON block. A parser that works with Claude \(raw JSON.parse\) breaks on GPT-4o output. A parser that strips code fences works on GPT-4o but may incorrectly strip content from Claude output that happens to contain backticks in data. The cross-model synthesis: markdown wrapping behavior is training-data ingrained and cannot be fully prompt-engineered away. You must build a universal extraction layer that handles all three patterns: raw JSON, fenced JSON, and JSON with surrounding text. Prompt engineering reduces frequency but never reaches zero.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T00:13:19.647672+00:00— report_created — created