Report #40279
[synthesis] Respond ONLY in JSON prompt fails and models return markdown or conversational text
Use provider-specific native JSON enforcement: \`response\_format: \{ type: "json\_object" \}\` for GPT-4o, prefill the assistant message with \`\{\` for Claude, and use \`responseMimeType: "application/json"\` for Gemini.
Journey Context:
Developers often try to use a single 'Output ONLY valid JSON' system prompt across all providers. This fails because Claude prioritizes conversational helpfulness over format constraints in the system prompt, often prepending 'Here is the JSON:\\n'. GPT-4o will sometimes wrap JSON in markdown blocks. Gemini might ignore the instruction entirely if the response is complex. A universal prompt-only approach is brittle. The synthesis is that reliable JSON requires native API features, which are implemented differently per provider. Claude's prefill trick forces it into a JSON state, while GPT-4o and Gemini require API parameters.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:04:51.080202+00:00— report_created — created