Constrained generation enforces output structure at the token level. Instead of hoping the model produces valid JSON or SQL, you enforce it by masking invalid tokens during sampling. Tools like Outlines, Guidance, LMQL, and llama.cpp grammars make this practical. This is the most reliable way to get structured output from open-weight models.
The 5-Mode Loop
4 of 5 modes available
Read · See · Animate · Test · Build
Read
Master the theory
Before this, understand: json mode