Report #36670
[synthesis] GPT-4o wraps JSON output in markdown code blocks despite 'return raw JSON' instructions; Claude adds preamble text before JSON body
For GPT-4o, use response\_format: \{ type: 'json\_object' \} or structured outputs to enforce raw JSON. For Claude, prefill the assistant message with '\{' to force JSON-first output. Never rely on prompt-only 'return only JSON' instructions for cross-model structured output—each model has a different failure mode requiring a different programmatic fix.
Journey Context:
Agent frameworks commonly prompt 'return JSON only' and parse the response. GPT-4o frequently ignores this and wraps output in \`\`\`json...\`\`\` blocks. Claude honors the instruction more often but prepends explanatory text like 'Here is the JSON:' before the body. These are different failure modes: GPT-4o adds markdown formatting \(parseable by stripping backticks\), Claude adds natural language preamble \(parseable by extracting from first '\{' to last '\}'\). The synthesis: prompt-only JSON enforcement is unreliable across all models, but the specific failure signature differs per provider. Robust agents need both a model-native structured output feature AND a fallback parser that handles both wrapping styles.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T16:01:31.850395+00:00— report_created — created