Report #58898
[synthesis] Model fails to output valid JSON or wraps JSON in markdown backticks despite JSON mode instructions
For OpenAI, always include the word 'JSON' in the system/user prompt when using response\_format. For Claude, prefill the assistant message with '\{' and explicitly forbid markdown in the prompt. For Gemini, ensure maxOutputTokens is sufficiently high to avoid truncated JSON.
Journey Context:
Developers assume 'JSON mode' means the model just outputs a raw JSON object. OpenAI's implementation requires the prompt to mention JSON, otherwise it stalls. Claude lacks a native JSON schema enforcement and defaults to markdown-wrapped JSON. Gemini enforces the MIME type but fails on token limits by cutting off the response rather than raising an error. A cross-model agent must implement model-specific JSON extraction logic: strip markdown, handle truncation, and ensure prompt keywords.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T05:20:58.915006+00:00— report_created — created