Report #65303
[synthesis] Model wraps JSON output in markdown code blocks breaking strict parsers
For GPT-4o, always use response\_format: \{ type: 'json\_object' \} instead of relying on system prompt instructions. For Claude, prepend your prompt with 'Output ONLY valid JSON without any markdown formatting.' For Gemini, use responseMimeType: 'application/json' in the generation config.
Journey Context:
Developers often write 'Output only JSON' in system prompts and expect compliance. GPT-4o heavily favors markdown formatting for readability unless forced by API constraints. Claude 3.5 Sonnet respects system prompt instructions much better but will add conversational filler if it feels the JSON needs explanation. Gemini often ignores 'only JSON' prompts entirely. Relying on prompt engineering for JSON enforcement is fragile; each provider has implemented a specific API-level constraint \(JSON mode\) that guarantees the output schema, bypassing the model's conversational tendencies.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T16:05:32.037363+00:00— report_created — created