# mlc-ai/xgrammar

Fast, Flexible and Portable Structured Generation

Repository: https://github.com/mlc-ai/xgrammar
Canonical: https://ross.abutalabs.com/products/xgrammar
Homepage: https://xgrammar.mlc.ai/docs
Language: C++
License: Apache-2.0
License Family: permissive
Topics: large-language-models, structured-generation
Last push: 2026-08-20T20:56:09+00:00

## Health v2 (maintenance only)
Score: 88/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 98, release rhythm 94, longevity 56
- inputs: {"age_days": 796, "days_push": 13, "days_rel": 43, "gap_med": 16.0, "n_releases_24m": 33}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 1843, forks 192 (observed 2026-08-28T04:05:43.269968+00:00)

## What it is
XGrammar is an open-source library for efficient, flexible, and portable structured generation in LLM inference via constrained decoding. It guarantees structurally correct outputs (JSON, regex, context-free grammars) with near-zero overhead and integrates into engines like vLLM, SGLang, and TensorRT-LLM.

## Use cases
- force an LLM to output valid JSON matching a schema
- constrain model outputs to a regex or context-free grammar
- reliable tool calling and function calling for LLMs
- add structured output support to a custom LLM inference engine
- guarantee 100% syntactically correct model generations
- generate structured outputs with low latency overhead

## When to choose
- you need guaranteed-valid structured output from an LLM
- you want near-zero overhead constrained decoding at scale
- you need portability across platforms, languages, and inference engines
- you support general grammars beyond simple JSON schemas

## When to avoid
- you only need unconstrained free-form text generation
- you want a full LLM serving stack rather than a structured generation library
- your use case is simple prompt-based formatting without hard guarantees

## Facets
- artifact type: library
- maturity: active
- function: llm-inference, parser, serialization, sdk
- domain: large-language-models, machine-learning, developer-tools
- platform: python, cpp, cross-platform, wasm
- tags: constrained-decoding, structured-output, json-schema, grammar, ebnf, tool-calling, llm-engine-integration, gpu, javascript

## Member repositories
- mlc-ai/xgrammar (main) score 88

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:05:43.269968+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-30T03:17:58.092087+00:00, confidence not recorded.
  - readme: https://github.com/mlc-ai/xgrammar (fetched 2026-08-28T04:05:43.269968+00:00, sha 2406a2e6c7f1)
  - homepage: https://xgrammar.mlc.ai/docs (fetched 2026-08-29T10:56:55.446521+00:00, sha 999a463d2590)
  - site_page: https://xgrammar.mlc.ai/docs/latest (fetched 2026-08-29T10:56:55.448966+00:00, sha 7e00539616a3)
- Data as of 2026-08-30T08:39:29.467469+00:00.
