Report #60504
[frontier] My agent hallucinates JSON output keys or returns wrong types, breaking downstream code
Use OpenAI Structured Outputs with \`strict: true\` \(or Zod schema binding\): define your output schema and let the model enforce it at the token level, preventing hallucinated keys or type mismatches.
Journey Context:
Developers parse JSON from agent outputs with regex, hitting 'unexpected token' errors when the model wraps JSON in markdown or hallucinates keys. OpenAI's Structured Outputs \(mid-2024, now standard in 2025\) constrains the model to valid JSON schemas at the logit level, guaranteeing type safety. Most tutorials still show \`JSON.parse\(\)\` on raw output. This pattern eliminates an entire class of agent output errors and enables reliable chaining of agents where strict schemas act as contracts between components.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:02:42.483788+00:00— report_created — created