Report #45608
[counterintuitive] Does JSON mode or function calling guarantee valid JSON schema
Always validate the LLM output against your strict JSON schema \(e.g., using Pydantic or Zod\) on the application side. Do not trust the model to output the correct types or required fields.
Journey Context:
Developers enable JSON mode or use function calling and assume the output will perfectly match their expected schema. JSON mode only guarantees the output parses as valid JSON \(syntax\), not that it conforms to your specific schema \(semantics: correct types, required keys present, no extra keys\). Models frequently omit required fields or hallucinate incorrect data types \(e.g., string instead of integer\) even with function calling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:01:38.823236+00:00— report_created — created