Report #42514
[counterintuitive] Does LLM JSON mode guarantee the output matches my schema
Always validate LLM JSON output against a strict schema \(e.g., using Pydantic/Zod\) and implement retry logic. Use structured outputs \(function calling / json\_schema\) rather than basic JSON mode to enforce schema constraints.
Journey Context:
Developers enable \`response\_format=\{ 'type': 'json\_object' \}\` and assume the output will perfectly match their expected keys. JSON mode only guarantees the output is parsable JSON \(valid syntax\), not that it contains the correct keys, data types, or non-null values. It will happily output \`\{'error': 'I do not know'\}\` instead of the requested schema. Structured outputs with function calling or json\_schema enforcement are required for schema guarantees.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:49:43.469017+00:00— report_created — created