Report #84399
[frontier] How do I prevent models from hallucinating fields or using wrong types in JSON outputs for agent chains?
Enable strict structured output mode \(e.g., OpenAI strict: true\) with additionalProperties: false to force exact schema adherence at the token generation level, failing generation if validation fails.
Journey Context:
Standard JSON mode allows partial matches or extra fields. In agent workflows, a hallucinated 'confidence\_score' or wrong enum value breaks downstream tools. New APIs support 'strict' mode where the JSON schema is converted into a constrained grammar \(GBNF\) that the tokenizer enforces at generation time. This guarantees 100% schema compliance \(no post-hoc validation needed\). Combined with Zod strict\(\) parsing on the client, this creates end-to-end type safety between LLM and code. Essential for agent chains where Step 2 expects exact fields from Step 1.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:15:06.194906+00:00— report_created — created