Report #46777
[synthesis] Claude adds unsolicited safety caveats breaking JSON parsing
Use Anthropic's tool use format for strict JSON extraction instead of prompting for raw JSON blocks, and for GPT-4o use Structured Outputs/JSON mode.
Journey Context:
When asked to output raw JSON, Claude 3.5 Sonnet frequently prepends safety caveats like 'While I cannot execute code, here is the JSON:' which breaks JSON.parse\(\). GPT-4o rarely does this if JSON mode is enabled, but might add conversational filler otherwise. Developers try to fix this with 'OUTPUT ONLY JSON NO MARKDOWN' prompts, which works inconsistently for Claude. The cross-model synthesis is that prompt-based JSON extraction is fragile; using the native tool calling API \(forcing the model to output arguments directly\) bypasses the conversational pre-text layer entirely in both providers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T08:59:18.166481+00:00— report_created — created