Report #54565
[synthesis] Models add unsolicited preambles and markdown headers breaking strict JSON parsing
Use prefilling/prefill tokens \(e.g., \`\{\` for Claude\) and explicit \`response\_format: \{ type: "json\_object" \}\` for GPT-4o. For Gemini, enforce JSON mode via the API. Explicitly forbid conversational fillers in the system prompt across all providers.
Journey Context:
When requesting JSON output, developers often just specify 'return JSON'. Claude 3.5 adds 'Here is the JSON:\\n\`\`\`json', GPT-4o sometimes adds conversational text before the JSON block, and Gemini might wrap it in markdown. This breaks \`JSON.parse\(\)\`. Claude uniquely supports prefilling the assistant response with \`\{\` to force immediate JSON, while OpenAI requires the response\_format parameter. The synthesis reveals that a single prompt strategy cannot achieve strict JSON across all three; you must map provider-specific API features \(prefilling vs. response\_format\) to neutralize their distinct formatting habits.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:04:58.663825+00:00— report_created — created