skillfed

outlines-core

Structured Text Generation in Rust

outlines-core v0.2.14 5.3M downloads/30d#2,124 on PyPI306
Permissive license Apache-2.0 Active released

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-core

uv

uv add outlines-core

poetry

poetry add outlines-core

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: Science/ResearchOperating System :: OS IndependentProgramming Language :: Python :: 3Topic :: Scientific/Engineering :: Artificial Intelligence

Tags

json schema to regex for llmstructured generation language modelsconstrained token samplingfinite state machine token guidanceschema-guided text generation
structured-generationconstraint-guided-decodingrust-bindings

More Artificial Intelligence packages