Restrict model outputs using grammars, regex, or token masks — guaranteeing valid format without post-hoc validation.
Five passes over the same idea, each from a different angle. Do them in order, or jump to whichever you need.
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.