Report #74860
[synthesis] Model returns conversational text alongside JSON despite JSON mode being enabled
For GPT-4o, explicitly include 'Respond only with JSON, no markdown' in the system prompt even when using response\_format: json\_object. For Claude, use the assistant prefill '\{' to force JSON and block conversational text. For Gemini, use responseMimeType: application/json but add a system instruction forbidding markdown.
Journey Context:
It is commonly believed that enabling JSON mode on an API guarantees pure JSON output. However, GPT-4o frequently wraps JSON in markdown blocks or adds 'Here is the JSON:' if not explicitly forbidden. Claude will output conversational text before the JSON if the prefill trick isn't used. Gemini sometimes adds conversational post-amble. The synthesis reveals that JSON mode APIs only guarantee valid JSON syntax within the response, not that the entire response is exclusively JSON; model-specific guardrails are required to prevent token waste and parsing errors.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:15:07.568425+00:00— report_created — created