Report #6548
[tooling] LLM outputs invalid JSON or structured data requiring expensive retry loops
Use \`--grammar-file grammar.gbnf\` \(or \`-gf\`\) with a GBNF grammar file to constrain token generation at the sampler level, guaranteeing valid syntax without retries.
Journey Context:
Instead of prompting 'Output valid JSON' and parsing/retrying on failure, GBNF grammars enforce output structure during token selection. The sampler only considers tokens that keep the partial output valid according to the grammar, eliminating retries entirely and reducing tokens spent on error corrections. While JSON mode restricts output format, GBNF supports arbitrary schemas \(JSON, regex, custom DSL\) with negligible performance overhead compared to retry loops. This is underused because it requires writing a grammar file rather than a simple prompt instruction.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T00:20:21.216120+00:00— report_created — created