outlines-core
Structured Text Generation in Rust
What it is and what it does
Outlines-core is a Rust-based library that enforces structured output from language models by converting JSON schemas into regular expressions and finite-state automata. It maps tokens from a model's vocabulary to valid state transitions, ensuring that only tokens that conform to the schema are allowed at each generation step. The package provides Python bindings alongside its core Rust implementation, making it accessible to Python developers while maintaining performance.
The library is designed for use cases where language model output must strictly conform to a predefined structure—such as generating JSON objects, dates, or other formatted data. It works by first building a regex from a JSON schema, then creating an Index that combines that regex with a Vocabulary (typically loaded from a pretrained model like GPT-2). A Guide object then tracks the current state and returns allowed tokens at each step, allowing downstream generation code to enforce the constraint.
Use it for:
- Generate valid JSON objects from language models by constraining output to match a schema.
- Enforce date, time, or other format-specific string generation in structured outputs.
- Build token-level guidance systems that prevent invalid state transitions during decoding.
- Integrate schema-based constraints into language model inference pipelines.
- Create finite-state machines for constrained text generation in production systems.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Outlines-core provides structured text generation for language models by converting JSON schemas into finite-state automata that constrain token selection during generation.
Yes, if you need to enforce structured output from language models. The package is actively maintained, has no known vulnerabilities, and offers a well-designed API for schema-guided generation. Medium install friction (compiled Rust bindings) is a minor trade-off for the performance and correctness guarantees it provides. Not necessary if your use case tolerates unstructured or post-hoc validation of model outputs.
Install
outlines-core on PyPI
pip
pip install outlines-coreuv
uv add outlines-corepoetry
poetry add outlines-coreInstalling outlines-core
Before you install
Medium install friction due to compiled Rust bindings across multiple platforms (Windows, macOS, Linux, ARM). Active maintenance with recent commits and stable production status.
License in practice
Apache-2.0 permissive license allows commercial use, modification, and redistribution with minimal restrictions—suitable for most projects.
Quickstart
import json
from outlines_core.json_schema import build_regex_from_schema
from outlines_core.guide import Guide, Index, Vocabulary
schema = {"type": "object", "properties": {"name": {"type": "string"}}}
regex = build_regex_from_schema(json.dumps(schema))
vocabulary = Vocabulary.from_pretrained("openai-community/gpt2")
index = Index(regex, vocabulary)
guide = Guide(index)
allowed_tokens = guide.get_tokens()
Requires Python >=3.8; prebuilt wheels available for cp310, cp311, cp312 on Windows, macOS (arm64/x86_64), and Linux (x86_64/aarch64)—other platforms may need compilation.
Verify before relying
- Whether the package works with language models other than GPT-2 for vocabulary loading.
- Performance characteristics and scalability limits for large schemas or vocabularies.
- Compatibility with specific tokenizer formats beyond what is documented in the example.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 217 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 5,277,655/month — #2,124 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: outlines_core-0.2.14-cp310-cp310-macosx_14_0_arm64.whl; outlines_core-0.2.14-cp310-cp310-macosx_14_0_x86_64.whl; outlines_core-0.2.14-cp310-cp310-macosx_15_0_arm64.whl; outlines_core-0.2.14-cp310-cp310-macosx_15_0_x86_64.whl; outlines_core-0.2.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; outlines_core-0.2.14-cp310-cp310-manylinux_2_28_aarch64.whl; outlines_core-0.2.14-cp310-cp310-win32.whl; outlines_core-0.2.14-cp310-cp310-win_amd64.whl; outlines_core-0.2.14-cp311-cp311-macosx_14_0_arm64.whl; outlines_core-0.2.14-cp311-cp311-macosx_14_0_x86_64.whl; outlines_core-0.2.14-cp311-cp311-macosx_15_0_arm64.whl; outlines_core-0.2.14-cp311-cp311-macosx_15_0_x86_64.whl; outlines_core-0.2.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; outlines_core-0.2.14-cp311-cp311-manylinux_2_28_aarch64.whl; outlines_core-0.2.14-cp311-cp311-win32.whl; outlines_core-0.2.14-cp311-cp311-win_amd64.whl; outlines_core-0.2.14-cp312-cp312-macosx_14_0_arm64.whl; outlines_core-0.2.14-cp312-cp312-macosx_14_0_x86_64.whl; outlines_core-0.2.14-cp312-cp312-macosx_15_0_arm64.whl; outlines_core-0.2.14-cp312-cp312-macosx_15_0_x86_64.whl
Keywords: machine learning, deep learning, language models, structured generation
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
cohere-melodyParses and renders templated text for Cohere…
permissive · top 15,000 on PyPI
lm-format-enforcerConstrains language model token generation to…
permissive · top 5,000 on PyPI
AutomatAutomat provides a Python library for building…
permissive · top 5,000 on PyPI
xgrammarConstrains LLM text generation to follow…
permissive · top 5,000 on PyPI
tree-sitter-regexProvides a tree-sitter grammar for parsing…
permissive · top 5,000 on PyPI
fastokensfastokens is a high-performance BPE tokenizer…
unclear · top 15,000 on PyPI
llguidanceEnforces structured output from large language…
permissive · top 5,000 on PyPI
tree-sitter-htmlProvides an HTML grammar for tree-sitter,…
permissive · top 5,000 on PyPI
text-generationProvides a Python client to query text…
permissive · top 15,000 on PyPI
tree-sitter-jsonProvides a JSON grammar parser for tree-sitter,…
permissive · top 5,000 on PyPI