Report #35347
[counterintuitive] Does LLM JSON mode guarantee valid JSON schema
Use an explicit schema enforcement library like \`instructor\` or \`guardrails\` alongside JSON mode, or use Structured Outputs \(if available\) which constrains the grammar. JSON mode only guarantees the output parses as valid JSON, not that it conforms to your specific required keys, types, or Pydantic schema.
Journey Context:
Developers enable \`response\_format=\{ 'type': 'json\_object' \}\` and assume the output will match their requested schema. The model only guarantees syntactic JSON validity \(matching braces/quotes\), but will frequently omit required fields, hallucinate extra fields, or use wrong data types \(e.g., string instead of int\) unless strictly constrained by a grammar engine or post-validated.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T13:47:58.146675+00:00— report_created — created