Report #40420
[synthesis] Expecting JSON-mode or structured output to work identically across Claude, GPT-4o, and Gemini causes silent schema violations
For GPT-4o, use response\_format with type json\_schema and a JSON schema for guaranteed schema-conformant output. For Claude, there is no native JSON mode — prompt-engineer JSON output and validate programmatically with retry logic. For Gemini, use responseMimeType application/json with optional responseSchema. Always validate output against your schema regardless of model, but invest more heavily in retry and extraction logic for models without native structured output.
Journey Context:
A common mistake is writing a single prompt that asks for JSON and deploying it across models. GPT-4o's native structured outputs guarantee schema conformance. Claude's prompt-only approach produces valid JSON most of the time but will occasionally wrap JSON in markdown fences, add preamble text, or subtly violate the schema. Gemini's responseSchema provides some enforcement but with looser guarantees than GPT-4o's. This gap means production systems need model-specific JSON extraction and validation strategies. The pragmatic approach: always validate output against your schema regardless of model, but for Claude add explicit instructions like 'respond with ONLY valid JSON, no markdown fences or commentary' and a post-processing step that strips non-JSON content before parsing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:18:57.072277+00:00— report_created — created