← all repositories

noamgat/lm-format-enforcer

A Python library that enforces structured output formats (JSON Schema, Regex) on language models by filtering allowed tokens during generation.

lm-format-enforcer
Not currently ranked — collecting fresh signals.
star history

The library addresses the common problem of language models failing to consistently produce outputs in requested formats. It works by wrapping generation calls and filtering the token vocabulary at each inference step to only allow tokens consistent with the specified schema or regex pattern. This approach ensures format compliance without requiring additional prompt engineering or retraining. It integrates with popular libraries like transformers and supports Pydantic models for defining JSON schemas.

Frequently asked

What is noamgat/lm-format-enforcer?
A Python library that enforces structured output formats (JSON Schema, Regex) on language models by filtering allowed tokens during generation.
Is lm-format-enforcer open source?
Yes — noamgat/lm-format-enforcer is open source, released under the MIT license.
What language is lm-format-enforcer written in?
noamgat/lm-format-enforcer is primarily written in Python.
How popular is lm-format-enforcer?
noamgat/lm-format-enforcer has 2k stars on GitHub.
Where can I find lm-format-enforcer?
noamgat/lm-format-enforcer is on GitHub at https://github.com/noamgat/lm-format-enforcer.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.