lm-format-enforcer
Enforce the output format (JSON Schema, Regex etc) of a language model
Enforce the output format (JSON Schema, Regex etc) of a language model
To install this package, run one of the following:
Language models are able to generate text, but when requiring a precise output format, they do not always perform as instructed. Various prompt engineering techniques have been introduced to improve the robustness of the generated text, but they are not always sufficient. This project solves the issues by filtering the tokens that the language model is allowed to generate at every timestep, thus ensuring that the output format is respected, while minimizing the limitations on the language model.
Summary
Enforce the output format (JSON Schema, Regex etc) of a language model
Last Updated
Jan 7, 2026 at 21:29
License
MIT
Total Downloads
36
Supported Platforms
GitHub Repository
https://github.com/noamgat/lm-format-enforcerDocumentation
https://github.com/noamgat/lm-format-enforcer