Report #84600
[frontier] Agents generate invalid tool call formats or hallucinate parameters despite JSON schemas
Use constrained decoding \(grammar-based generation\) where the LLM's output probability is masked to only valid schema tokens at each step, combined with a validation loop that feeds schema errors back as context for retries. Implement via OpenAI's Structured Outputs or outlines/libtmpl for open models.
Journey Context:
Post-hoc validation \(generate then parse\) is unreliable because the model commits to hallucinated tokens before validation occurs. Prompt engineering \('You must output valid JSON'\) is ineffective at the token level. Constrained decoding \(also called 'grammar-based sampling' or 'constrained generation'\) restricts the logits at each step to tokens that maintain schema validity. This makes invalid outputs structurally impossible. The validation loop adds resilience: if constrained generation still fails \(rare edge cases\), the error is captured and injected into the next attempt's context \('Previous attempt failed because X'\). This is superior to simple retry loops. The alternative \(function calling without constrained decoding\) shows 5-15% error rates in production. This pattern is becoming mandatory for reliable agent tool use.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:35:40.668047+00:00— report_created — created