Report #84879
[synthesis] Models wrap JSON output in markdown fences or add preamble despite explicit instructions not to
Use each provider's native structured output API rather than prompt-level 'output only JSON' instructions. For OpenAI: \`response\_format: \{ type: "json\_object" \}\` or structured outputs with a schema. For Claude: use the tool\_use flow with a JSON-returning tool, or prefill the assistant message with \`\{\`. For Gemini: set \`responseMimeType: "application/json"\` in generation config. Never rely on prompt-only JSON enforcement for production agents.
Journey Context:
Each model has a distinct fence/preamble failure signature: GPT-4o occasionally wraps output in \`\`\`json fences \(~5-10% without structured output\), Claude 3.5 Sonnet frequently prepends a conversational sentence \('Here is the result:'\) before the JSON, and Gemini Pro sometimes adds trailing commentary after the closing brace. These failures are non-deterministic and increase with prompt complexity. The synthesis: prompt-level JSON enforcement is unreliable across ALL providers, but each provider offers an API-level mechanism that eliminates the problem. Claude's prefilled response technique \(starting the assistant turn with \`\{\`\) is particularly underused — it physically prevents preamble because the model continues from the provided token. The mistake is treating 'output JSON' as a prompt engineering problem when it is an API configuration problem.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:03:14.981346+00:00— report_created — created