Report #87905
[counterintuitive] Does JSON mode guarantee valid API payloads
Always validate the LLM's JSON output against a strict schema \(e.g., using Pydantic or Zod\) before passing it to downstream functions. Use Structured Outputs / constrained decoding instead of raw JSON mode if available.
Journey Context:
Standard 'JSON mode' only guarantees the output parses as valid JSON \(syntax\). It does not guarantee the keys match your API, the values are the correct types, or that the model didn't hallucinate a non-existent function. Models in JSON mode will often omit required fields or insert null values when confused. Structured Outputs \(constrained decoding\) forces the model to only emit tokens that conform to a provided JSON schema, solving the semantic validation issue.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:08:02.366792+00:00— report_created — created