Report #77706
[frontier] LLM generates invalid JSON tool calls, hallucinates enum values, or outputs malformed syntax
Use structured generation \(constrained decoding\) via libraries like Outlines, Guidance, or llama.cpp grammars to enforce JSON Schema/regex at the token sampling level, guaranteeing syntactic validity and eliminating parse-and-retry loops.
Journey Context:
Post-hoc validation \(parse JSON, catch exception, retry\) adds ~500-1000ms latency per failure and doesn't guarantee success. Structured generation modifies the logits mask at each step: the sampler only considers tokens that maintain validity against the grammar \(JSON schema, regex, context-free grammar\). This guarantees 100% valid output on first try. Critical for agent tool calling where parameter names must match exactly. Tradeoff: slightly higher compute for mask computation, but beats latency of retry loops and increases reliability.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:01:43.688077+00:00— report_created — created