# noamgat/lm-format-enforcer

Enforce the output format (JSON Schema, Regex etc) of a language model

Repository: https://github.com/noamgat/lm-format-enforcer
Canonical: https://ross.abutalabs.com/products/lm-format-enforcer
Language: Python
License: MIT
License Family: permissive
Last push: 2026-04-04T14:57:50+00:00

## Health v2 (maintenance only)
Score: 64/100 (v2, computed 2026-09-02T17:46:02.011165+00:00)
- activity 75, release rhythm 42, longevity 76
- inputs: {"age_days": 1077, "days_push": 151, "days_rel": 389, "gap_med": 11, "n_releases_24m": 8}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 2029, forks 92 (observed 2026-08-28T04:06:07.062911+00:00)

## What it is
A Python library that enforces output formats like JSON Schema or regex on language models by filtering allowed tokens at each generation step. It integrates with transformers, LangChain, llama.cpp, vLLM, and other inference stacks.

## Use cases
- force an LLM to output valid JSON matching a schema
- make a language model follow a regex output pattern
- get structured data extraction from LLM responses
- prevent malformed JSON from a chat model
- constrain model output to a pydantic model schema
- guarantee parseable LLM output for downstream pipelines

## When to choose
- you need guaranteed schema-valid or regex-valid LLM output
- you use Hugging Face transformers, vLLM, llama.cpp, or LangChain and want constrained decoding
- prompt engineering alone isn't reliable enough for structured output

## When to avoid
- you need function-calling or structured output built into a hosted API like OpenAI's
- your model server already provides native grammar-constrained sampling
- you work outside the Python ecosystem

## Facets
- artifact type: library
- maturity: active
- function: llm-inference, parser, prompt-engineering, serialization
- domain: large-language-models, machine-learning, developer-tools
- platform: python
- tags: structured-output, -schema, constrained-decoding, regex-enforcement, token-filtering, langchain-integration, transformers, natural-language-processing

## Member repositories
- noamgat/lm-format-enforcer (main) score 64

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:06:07.062911+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T02:59:38.272142+00:00, confidence not recorded.
  - readme: https://github.com/noamgat/lm-format-enforcer (fetched 2026-08-28T04:06:07.062911+00:00, sha c862ee8ec38a)
  - registry_pypi: https://pypi.org/pypi/lm-format-enforcer/json (fetched 2026-08-29T10:39:42.352938+00:00, sha 77fca9570aba)
- Data as of 2026-08-30T08:39:29.467469+00:00.
