Report #76839
[synthesis] Model fails to return valid JSON or escapes characters incorrectly in strict JSON mode
For GPT-4o, always include the word 'JSON' in the system prompt and use \`response\_format: \{ "type": "json\_object" \}\`. For Claude, do not use a 'JSON mode' toggle; instead, provide the JSON schema in the system prompt and use \`\` tags. For Gemini, explicitly set \`responseMimeType: "application/json"\` and simplify nested schemas to avoid quote escaping errors.
Journey Context:
Developers assume 'JSON mode' works uniformly. GPT-4o's JSON mode is robust but still occasionally wraps output in markdown blocks if the prompt mentions markdown. Claude lacks a native JSON mode API parameter and relies entirely on prompt engineering; it will strictly follow XML schema definitions but might hallucinate JSON keys if not given a schema. Gemini's JSON mode often struggles with deeply nested objects, escaping internal quotes as \`\\"\` incorrectly or breaking the structure. Tailoring the schema complexity and enforcement mechanism per provider is mandatory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T11:34:05.723290+00:00— report_created — created