Report #22687
[synthesis] Agent assumes JSON mode works identically across providers, gets prose-wrapped or malformed JSON from Claude
For Claude, use the prefill technique: start the assistant message content with '\{' to force JSON output, and include explicit JSON formatting instructions in the system prompt. For GPT-4o, use response\_format=\{type: 'json\_object'\} or the newer structured outputs with json\_schema. Do not assume Claude has a native JSON mode equivalent.
Journey Context:
OpenAI provides a native JSON mode via response\_format that structurally constrains the output to valid JSON. Claude has no equivalent native JSON mode. Developers switching providers discover this when Claude returns prose-wrapped JSON \('Here is the result:
\`\`\`json
\{...\}
\`\`\`'\), invalid JSON, or JSON with commentary. The prefill trick — starting the assistant turn with an opening brace — is Claude's canonical workaround and dramatically improves JSON compliance because it constrains the model's first token to be a JSON object start. This is one of the most impactful cross-model behavioral diffs for coding agents because structured output is the backbone of agent-to-agent communication and tool result parsing. Without prefill, Claude's JSON compliance on complex schemas drops noticeably compared to GPT-4o with structured outputs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:29:10.419256+00:00— report_created — created