outlines-core

Library Listed

Structured Generation

Downloads
2,320
Dependents
1
Stars
320
Forks
80
Contributors
30
Commits
249
Latest release
0.2.14 ·

About

From the project README ·

Outlines-core Logo

Structured generation (in Rust).

This package provides the core functionality for structured generation, formerly implemented in Outlines, with a focus on performance and portability, it offers a convenient way to:

  • build regular expressions from JSON schemas

  • construct an Index object by combining a Vocabulary and regular expression to efficiently map tokens from a given vocabulary to state transitions in a finite-state automation

Example

Basic example of how it all fits together.

Read the full README
use outlines_core::prelude::*;

// Define a JSON schema
let schema = r#"{
    "type": "object",
    "properties": {
        "name": { "type": "string" },
        "age": { "type": "integer" }
    },
    "required": ["name", "age"]
}"#;

// Generate a regular expression from it
let regex = json_schema::regex_from_str(&schema, None)?;

// Create `Vocabulary` from pretrained large language model (but manually is also possible)
let vocabulary = Vocabulary::from_pretrained("openai-community/gpt2", None)?;

// Create new `Index` from regex and a given `Vocabulary`
let index = Index::new(&regex, &vocabulary)?;

let initial_state = index.initial_state();
let allowed_tokens = index.allowed_tokens(&initial_state).expect("Some allowed token ids");
let token_id = allowed_tokens.first().expect("First token id");
let next_state = index.next_state(&initial_state, token_id);
let final_states = index.final_states();
Vocabulary

You can create a Vocabulary in three ways:

  1. Vocabulary::from_pretrained(model, parameters) - Loads from a pretrained model (as in the example above)

  2. Manual creation - You can create a vocabulary from token mappings:

    1. Vocabulary::new(eos_token_id) - Creates an empty vocabulary, then add tokens with try_insert():

      let mut vocabulary = Vocabulary::new(50256);
      vocabulary.try_insert("hello", 0)?;
      vocabulary.try_insert(vec![32], 1)?;
      
    2. Vocabulary::try_from((eos_token_id, tokens)) - Creates a vocabulary by directly providing the token mappings.

      • It can be done either with the tokens as strings:

        use rustc_hash::FxHashMap as HashMap;
        
        let eos_token_id: u32 = 50256;
        let mut tokens: HashMap<String, Vec<u32>> = HashMap::default();
        tokens.insert("hello".to_string(), vec![0]);
        tokens.insert("world".to_string(), vec![1]);
        
        let vocabulary = Vocabulary::try_from((eos_token_id, tokens))?;
        
      • Or with the tokens as byte vector keys:

        use rustc_hash::FxHashMap as HashMap;
        
        let eos_token_id: u32 = 50256;
        let mut tokens: HashMap<Vec<u8>, Vec<u32>> = HashMap::default();
        tokens.insert(b"hello".to_vec(), vec![0]);
        tokens.insert(b"world".to_vec(), vec![1]);
        
        let vocabulary = Vocabulary::try_from((eos_token_id, tokens))?;
        

Important: When creating a Vocabulary manually from tokenizer data, ensure tokens are converted to their string representations to replace special tokens that wouldn't be recognized by the DFA.

Python Bindings

Additionally, project provides interfaces to integrate the crate's functionality with Python.

import json

from outlines_core.json_schema import build_regex_from_schema
from outlines_core import Guide, Index, Vocabulary

schema =  {
  "title": "Foo",
  "type": "object",
  "properties": {"date": {"type": "string", "format": "date"}}
}
regex = build_regex_from_schema(json.dumps(schema))

vocabulary = Vocabulary.from_pretrained("openai-community/gpt2")
index = Index(regex, vocabulary)
guide = Guide(index)

# Get current state of the Guide:
current_state = guide.get_state()

# Get allowed tokens for the current state of the Guide:
allowed_tokens = guide.get_tokens()

# Advance Guide to the next state via some token_id and return allowed tokens for that new state:
next_allowed_tokens = guide.advance(allowed_tokens[-1])

# To check if Guide is finished:
guide.is_finished()

# If it's finished then this assertion holds:
assert guide.get_tokens() == [vocabulary.get_eos_token_id()]

How to contribute?

Setup

Fork the repository on GitHub and clone the fork locally:

git clone git@github.com/YourUserName/outlines-core.git
cd outlines-core

Create a new virtual environment and install the dependencies in editable mode:

python -m venv .venv
source .venv/bin/activate
pip install -e ".[test]"
pre-commit install
Before pushing your code

If working with Python bindings don't forget to build Rust extension before testing, for example, in debug mode:

make build-extension-debug

Run Python tests:

pytest

Run Rust tests:

cargo test

Or alternatively using Makefile for both:

make test

Finally, run the code style checks:

pre-commit run --all-files

Or using Makefile:

make pcc

If necessary you can run benchmarks locally:

make pybench

Join us

  • 💡 Have an idea? Come chat with us on Discord
  • Found a bug? Open an issue
Runs on
GPU support unknown
What shows it
  • no dependency or feature matches a backend row
Native code
None found
  • No native code found
Python bindings
Has Python bindings
  • outlines-core needs Python only with feature python-bindings
License
Apache-2.0

Compare with similar projects

Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.

outlines-core beside the projects that share a topic with it
ProjectDownloadsDependentsStarsLatest releaseRuns on (GPU)Native codeLicense
outlines-core This page Listed

Structured Generation

Python bindings

2,320 downloads over 30 days 1 320 0.2.14 GPU support unknown No native code found Apache-2.0
ort Featured

A safe Rust wrapper for ONNX Runtime 1.31 - Optimize and accelerate machine learning inference & training

Also in Run and serve models.

3,902,768 downloads over 30 days 694 2,611 2.0.0-rc.15 CUDA, WebGPU, ROCm Binds native code: onnxruntime, ort-sys. Build uses a native toolchain: pkg-config (feature pkg-config) Apache-2.0 OR MIT
rten Featured

Tensor library for the RTen machine learning runtime

Also in Run and serve models.

496,924 downloads over 30 days 29 360 0.27.0 GPU support unknown No native code found Apache-2.0 OR MIT
llguidance Featured

LLM Token Trie library

Also in Build LLM apps and agents.

182,570 downloads over 30 days 22 909 1.9.1 GPU support unknown No native code found MIT
mistralrs App Featured

Fast, flexible LLM inference.

Python bindings

Also in Build LLM apps and agents.

1,498 binary downloads per release Not applicable 7,819 0.8.1 CUDA, Metal Binds native code: accelerate-src (feature accelerate-src), intel-mkl-src (feature intel-mkl-src) MIT
dynamo App Listed

A Datacenter Scale Distributed Inference Serving Framework

Also in Build LLM apps and agents.

6,860 downloads over 30 days Not applicable 8,457 1.6.2 CUDA Binds native code: k8s-openapi, nixl-sys, pcre2-sys, ring, zmq-sys and 2 more Apache-2.0
blazr App Listed

Inference server for LLMs, speech and embeddings: OpenAI-compatible routes with streaming, plus speech synthesis (TTS) and transcription (ASR). Serves Llama, Mistral, Qwen, Mamba2, MLA+MoE and hybrid models from SafeTensors, AWQ, GPTQ and GGUF.

Also in Build LLM apps and agents.

8 binary downloads per release Not applicable 7 0.7.1 CUDA, WebGPU Binds native code: ring (feature distributed) Apache-2.0
Why ListedNo archive, New or Featured rule places it, so it is Listed.

What it lacks for Featured

  • It has 1 active dependents and 1 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days. The repository route reads 320 stars, 80 forks and 30 contributors. It needs 4,539 stars, 434 forks and 79 contributors together.

What else the check found

Check notes

  • the latest release was packaged from a dirty working tree

Exact rules: Listed, Featured library. The check on applied thresholds version 9.

Every rule outcome, as the check records it
  • expected-interval: version 0.2.14 base 450: E = 450 days
  • dormancy: last activity 2026-08-05, 96 days ago, E = 450: active
  • rot: deprecated requirement `bincode (RUSTSEC-2025-0141, https://rustsec.org/advisories/RUSTSEC-2025-0141.html)`
  • featured: not featured: active_users 1 < 11 and new_adopters 1 < 9 and repository route stars 320 (needs 4539), forks 80 (needs 434), contributors 30 (needs 79)
  • listed: listed: no archive, new or featured rule applies

Measurements and sources

Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.

Sources6 sources
Adoption1 active dependents, 1 new dependents in 365 days1 not measured
Adoption measurements
SignalValueSourceFetchedCounts
Active dependents1crates.io database dumpYes
New dependents (365 days)1crates.io database dumpYes
Peak active dependents1crates.io database dumpYes
Active dependents as a share of the peak1crates.io database dumpYes
Binary downloads per releaseNot measuredYes
MaintenanceLatest human commit: 3 months ago3 not measured
Maintenance measurements
SignalValueSourceFetchedCounts
Latest human commit2026-08-05GitHub repositoryYes
Latest release2026-01-09crates.io database dumpYes
First release2024-09-06crates.io database dumpYes
Latest version0.2.14crates.io database dumpYes
Days the oldest outside issue waits for a reply650GitHub repositoryYes
Maintainer replies over 365 days2GitHub repositoryYes
Repository archivedfalseGitHub repositoryYes
Repository gonefalseGitHub repositoryYes
Release commit or manifest in the repotruecrates.io packageYes
Published docstruecrates.io database dumpYes
Latest release fails cargo checkNot measuredYes
Build check dateNot measuredYes
Build check toolchainNot measuredYes
SecurityUnpatched vulnerabilities: none
Security measurements
SignalValueSourceFetchedCounts
Unpatched vulnerabilities past the grace windownoneRustSec advisory databaseYes
RustSec unmaintained advisorynoneRustSec advisory databaseYes
Deprecation noticenonecrates.io database dumpYes
Deprecated requirementbincode (RUSTSEC-2025-0141, https://rustsec.org/advisories/RUSTSEC-2025-0141.html)crates.io database dumpYes
Distribution19 releases, 2,320 downloads over 30 days5 not measured
Distribution measurements
SignalValueSourceFetchedCounts
Releases19crates.io database dumpYes
Downloads over 30 days2320crates.io database dumpYes
Binary downloads over the last 3 releasesNot measuredYes
Homebrew installs on request over 365 daysNot measuredYes
Repology repository familiesNot measuredYes
Docker pull growth over 90 daysNot measuredYes
Docker pulls at the growth baselineNot measuredYes
Every version a prereleasefalsecrates.io database dumpYes
Every version 0.0.xfalsecrates.io database dumpYes
Every version yankedfalsecrates.io database dumpYes
Crate deleted from crates.iofalsecrates.io database dumpYes
Repository320 stars, 80 forks, 30 contributors, 249 commits. Stars alone never qualify a project.
Repository measurements
SignalValueSourceFetchedCounts
GitHub stars320GitHub repositoryYes — one part of the repository route
GitHub forks80GitHub repositoryYes — one part of the repository route
Contributors with a GitHub account30GitHub contributorsYes — one part of the repository route
Commits on the default branch249GitHub repositoryNo
Repository's main crate left out of the entrynonecrates.io database dumpYes
Facts that never count
Facts that never count measurements
SignalValueSourceFetchedCounts
LicenseApache-2.0crates.io database dumpNo
Runs on, from listed crates and their direct dependenciesGPU support unknowncrates.io database dumpNo
What shows each backendno dependency or feature matches a backend rowcrates.io database dumpNo
Native code, from listed crates and their dependenciesNo native code foundcrates.io database dumpNo
Python bindings, from direct dependencies of listed cratesHas Python bindings: outlines-core needs Python only with feature python-bindingscrates.io database dumpNo
Crates that depend on a listed crate directly1crates.io database dumpNo

Corrections and review history

Report a correction

No correction applies to this entry.

Judgments

A judgment enters only through an approved issue and a merged pull request.

No judgment applies to this entry.