Report #36490
[synthesis] Claude outputs markdown-wrapped JSON or adds preamble despite JSON mode request; GPT-4o structured output is API-enforced
For GPT-4o, use \`response\_format: \{ type: 'json\_object' \}\` or the Structured Outputs feature for API-level enforcement. For Claude, you must add explicit prompt instruction: 'Respond ONLY with valid JSON. No markdown fences, no explanation, no preamble.' Additionally, strip any leading/trailing whitespace and remove markdown code fences post-hoc as a defensive parse step. Do not assume Claude's JSON output is clean without validation.
Journey Context:
GPT-4o's \`response\_format\` and Structured Outputs enforce JSON at the decoding/constraint level — the model physically cannot produce non-JSON output. Claude has no equivalent API-level enforcement; its JSON compliance is prompt-driven. Even with explicit JSON instructions, Claude may wrap output in \`\`\`json...\`\`\` fences, add a preamble sentence \('Here is the JSON:'\), or include trailing commentary. The failure signatures differ: GPT-4o JSON failures are semantic \(valid JSON with wrong values, schema violations within valid structure\), while Claude JSON failures are structural \(markdown wrapping, preamble text, mixed content\). A cross-model agent needs different parsing strategies: direct JSON parse for GPT-4o, pre-processing strip/extract for Claude. The defensive pattern is to always attempt JSON parse, and on failure, regex-extract content between the first \`\{\` and last \`\}\` or \`\[\` and \`\]\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:43:27.059038+00:00— report_created — created