Report #66774
[synthesis] JSON output wrapped in markdown blocks breaking JSON.parse\(\)
For Claude, use the 'tool use for structured extraction' pattern \(define a single output tool\) rather than prompting 'respond in JSON', as Claude respects tool schemas perfectly but defaults to markdown-wrapped JSON for text prompts. For GPT-4o, use \`response\_format\`.
Journey Context:
Developers often use the prompt 'Return a JSON object...' for all models. GPT-4o handles this reasonably well, especially with \`response\_format\`, outputting raw JSON. Claude 3.5 Sonnet, trained heavily on conversational markdown, will frequently wrap its JSON output in \`\`\`json blocks, adding conversational preamble, which breaks \`JSON.parse\(\)\`. The cross-model synthesis is that structured extraction in Claude is most reliably achieved by defining a 'dummy' tool whose only purpose is to accept the structured data, leveraging Claude's strict tool-use training.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:33:37.968658+00:00— report_created — created