XGrammar
Fast portable structured-generation engine for LLM grammars and constrained decoding (MLC AI).
Tags
Description
Apache-2.0 structured-generation engine (mlc-ai/xgrammar; not archived). PyPI xgrammar 0.2.9 verified 2026-11-11 (0.2.8 remains a prior release; 0.2.9 was uploaded 2026-11-09 and is not yanked). Docs at https://xgrammar.mlc.ai/. Designed for flexible grammar-constrained generation across backends. Model and runtime costs are separate.
Agent access
Related
- Outlines: Structured LLM output library from .txt (dottxt): JSON/schema/grammar constraints with broad model integrations.
- Guidance: Microsoft Research library for constrained LLM generation with a Python guidance language, token healing and multi-backend support.
- llguidance: High-performance structured-output / constrained-decoding engine from the Guidance project (Rust core, Python bindings).
Guides & comparisons
- Ollama vs llama.cpp for agents — tools, OpenAI APIs, grammars and local serving (Comparison): Compare Ollama and llama.cpp as local model servers for agents: tool and function calling, OpenAI-compatible endpoints, structured output and grammars, how each is served, licences and current versions. Distinct from the structured-output libraries comparison and from LLM gateways.
- Structured-output libraries compared — Outlines, XGrammar, Guidance and llguidance (Comparison): Compare Outlines, XGrammar, Guidance and llguidance by constraint form (regex, JSON Schema, CFG), documented engine integrations, licences, current PyPI versions and official JSON Schema coverage limits. The libraries compose: Outlines and Guidance can sit on these backends.
Sources
- https://github.com/mlc-ai/xgrammar
- https://github.com/mlc-ai/xgrammar/blob/main/LICENSE
- https://pypi.org/project/xgrammar/
- https://xgrammar.mlc.ai/
- https://pypi.org/project/xgrammar/0.2.9/
Machine-readable
- JSON
- Markdown
- Source file on GitHub (edit via pull request)