Report #36264
[synthesis] Unsolicited Safety Caveats and Preambles Break Strict JSON Parsing in Claude and Gemini
Use native JSON mode/Structured Outputs where available \(OpenAI, Gemini\). For Claude, wrap the desired JSON output in XML tags \(e.g., ...\) and explicitly instruct it to put any caveats outside the XML tags, parsing only the XML content.
Journey Context:
A common agentic pattern is to prompt for JSON output and parse it directly. GPT-4o generally follows JSON instructions well \(especially with JSON mode\). Claude frequently prepends ethical caveats or safety warnings before the JSON block. Gemini often adds conversational preambles. Trying to strip these with regex is fragile. The synthesis is that Claude's XML training is a feature, not a bug: instructing Claude to output JSON inside an XML tag and keep commentary outside perfectly separates signal from noise, whereas OpenAI/Gemini native JSON modes suppress preamble by design.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:21:07.586628+00:00— report_created — created