freshcrate
Skin:/
Home > RAG & Memory > outlines-core

outlines-core

Structured Text Generation in Rust

Why this rank:Strong adoptionHealthy release cadenceRelease freshness

Description

<div align="center" style="margin-bottom: 1em;"> <img src="./docs/assets/images/logo.png" alt="Outlines-core Logo" width=500></img> [![Latest Version]][crates.io] [![License]][github] ![MSRV][version] [Latest Version]: https://img.shields.io/crates/v/outlines-core.svg [crates.io]: https://crates.io/crates/outlines-core [License]: https://img.shields.io/github/license/dottxt-ai/outlines-core.svg?color=blue&cachedrop [github]: https://github.com/dottxt-ai/outlines-core/blob/main/LICENSE [MSRV]: MSRV [version]: https://img.shields.io/crates/msrv/outlines-core.svg?label=msrv&color=lightgrayy *Structured generation (in Rust).* </div> ## Outlines-core This package provides the core functionality for structured generation, formerly implemented in [Outlines][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. ```rust 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()`: ```rust 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: ```rust 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: ```rust 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. ``` python import json from outlines_core.json_schema import build_regex_from_schema from outlines_core.guide 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: ```bash git clone git@github.com/YourUserNam

Release History

VersionChangesUrgencyDate
0.2.14Imported from PyPI (0.2.14)Low4/21/2026
0.2.13## What's Changed * Add pyo3/generate-import-lib to the python-bindings in the Cargo file by @RobinPicard in https://github.com/dottxt-ai/outlines-core/pull/232 * Update STRING and STRING_INNER regex to support `\+/`, `\+b`, `\+f`, `\+n`, `\+r`, `\+t` in JSON schema by @quanliu1991 in https://github.com/dottxt-ai/outlines-core/pull/231 ## New Contributors * @quanliu1991 made their first contribution in https://github.com/dottxt-ai/outlines-core/pull/231 **Full Changelog**: https://githuLow10/15/2025
0.2.12## What's Changed * expose max_recursion_depth in build_regex_from_schema by @dariogod in https://github.com/dottxt-ai/outlines-core/pull/181 * Fix `cargo test` by @Zantier in https://github.com/dottxt-ai/outlines-core/pull/214 * json_schema: Allow const/enum to contain arrays and objects by @Zantier in https://github.com/dottxt-ai/outlines-core/pull/205 * Fix `cargo audit` in CI by @Zantier in https://github.com/dottxt-ai/outlines-core/pull/217 * Make the custom kernel for mlx type safe byLow10/15/2025
0.2.11## What's Changed * Allow building the lib for more flavors by @ykhrustalev in https://github.com/dottxt-ai/outlines-core/pull/200 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.2.10...0.2.11Low5/19/2025
0.2.10## What's Changed * Fix: Error when creating index from schema with Uri by @Zantier in https://github.com/dottxt-ai/outlines-core/pull/206 * Fix: Nix flake fails to run `cargo +nightly fmt` by @Zantier in https://github.com/dottxt-ai/outlines-core/pull/204 * add accepts, rollback methods on Guide and tests by @unaidedelf8777 in https://github.com/dottxt-ai/outlines-core/pull/212 ## New Contributors * @Zantier made their first contribution in https://github.com/dottxt-ai/outlines-core/pullLow5/12/2025
0.2.9## What's Changed * Fix issue publish workflow + restore maturin for upload by @RobinPicard in https://github.com/dottxt-ai/outlines-core/pull/208 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.2.8...0.2.9Low4/11/2025
0.2.8## What's Changed * Extend convert-json-schema with basic help by @ykhrustalev in https://github.com/dottxt-ai/outlines-core/pull/195 * Use pypa to publish to pypi instead of maturin by @RobinPicard in https://github.com/dottxt-ai/outlines-core/pull/207 ## New Contributors * @ykhrustalev made their first contribution in https://github.com/dottxt-ai/outlines-core/pull/195 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.2.7...0.2.8Low4/11/2025
0.2.7## What's Changed * Fix missing command in build_wheels workflow by @RobinPicard in https://github.com/dottxt-ai/outlines-core/pull/203 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.2.6...0.2.7Low4/4/2025
0.2.5## What's Changed * Add interface to `Guide` object to update masks in place, and associated kernels. by @unaidedelf8777 in https://github.com/dottxt-ai/outlines-core/pull/183 * Add --allow-dirty flag to cargo publish dry-run commands by @RobinPicard in https://github.com/dottxt-ai/outlines-core/pull/199 ## New Contributors * @RobinPicard made their first contribution in https://github.com/dottxt-ai/outlines-core/pull/199 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/cLow4/1/2025
0.2.4## What's Changed * Stabilize python guide tests by @414owen in https://github.com/dottxt-ai/outlines-core/pull/175 * Make pyo3 dependency optional by @414owen in https://github.com/dottxt-ai/outlines-core/pull/172 * Upgrade pyo3 to 0.23 by @414owen in https://github.com/dottxt-ai/outlines-core/pull/171 * Reproducible Python virtual environment using `uv` and `nix` by @yvan-sraka in https://github.com/dottxt-ai/outlines-core/pull/141 * Use `maturin` as a build backend and improve github worLow3/29/2025
0.2.3## What's Changed * Fix artifact conflict and macos version inconsistency by @torymur in https://github.com/dottxt-ai/outlines-core/pull/169 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.2.2...0.2.3Low2/4/2025
0.2.2## What's Changed * Pin QEMU to 8.1.5 by @torymur in https://github.com/dottxt-ai/outlines-core/pull/163 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.2.1...0.2.2Low1/31/2025
0.2.1## What's Changed * Update actions artifact by @torymur in https://github.com/dottxt-ai/outlines-core/pull/161 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.2.0...0.2.1Low1/30/2025
0.2.0## What's Changed * Build `Index` from regex by @torymur in https://github.com/dottxt-ai/outlines-core/pull/125 * Stabilization of `json_schema` by @torymur in https://github.com/dottxt-ai/outlines-core/pull/133 * Sort, clean and update .gitignore by @yvan-sraka in https://github.com/dottxt-ai/outlines-core/pull/140 * Add support for type in json schema to be a list by @bnjjj in https://github.com/dottxt-ai/outlines-core/pull/138 * Restructure and formatting updates by @torymur in https://Low1/30/2025
0.1.27## What's Changed * Support URI format by @sky-2002 in https://github.com/dottxt-ai/outlines-core/pull/129 * No release workflows on PRs by @torymur in https://github.com/dottxt-ai/outlines-core/pull/132 * Optimize output of non-required properties by @414owen in https://github.com/dottxt-ai/outlines-core/pull/130 * Add binary which converts JSON schemas to regex by @414owen in https://github.com/dottxt-ai/outlines-core/pull/131 * Email format in JSON schema by @sky-2002 in https://github.Low1/17/2025
0.1.26## What's Changed * Add Linux aarch64 by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/123 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.25...0.1.26Low12/12/2024
0.1.25## What's Changed * Allow threads on `Index` creation by @torymur in https://github.com/dottxt-ai/outlines-core/pull/121 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.24...0.1.25Low12/11/2024
0.1.24## What's Changed * Do not bump Cargo version before releasing to PyPi by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/120 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.23...0.1.24Low12/9/2024
0.1.23## What's Changed * Allow uncommitted VCS changes to be packaged in CI by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/119 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.22...0.1.23Low12/9/2024
0.1.22## What's Changed * Remove JSON Schema conversion tests ported to Rust by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/118 * Fix handling of the anything_else check by @iratebadger in https://github.com/dottxt-ai/outlines-core/pull/94 * Switch from HashMap -> FxHashMap for better compilation performance. by @unaidedelf8777 in https://github.com/dottxt-ai/outlines-core/pull/115 * Use a script to automatically set the version in `Cargo.toml` by @rlouf in https://github.com/dottxtLow12/9/2024
0.1.21## What's Changed * Support recursive references in json schema by @torymur in https://github.com/dottxt-ai/outlines-core/pull/98 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.20...0.1.21Low12/6/2024
0.1.20## What's Changed * Fix the MacOS wheel build by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/104 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.19...0.1.20Low12/6/2024
0.1.19## What's Changed * Fix Linux CI builds by installing OpenSSL by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/102 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.18...0.1.19Low12/5/2024
0.1.18## What's Changed * Extend Vocabulary by @torymur in https://github.com/dottxt-ai/outlines-core/pull/88 * fix: Handle Salamandra and OpenCoder tokenizers by @saattrupdan in https://github.com/dottxt-ai/outlines-core/pull/90 * Make `RegexGuide` pickleable again for `vllm` and `tgi` by @joennlae in https://github.com/dottxt-ai/outlines-core/pull/99 ## New Contributors * @saattrupdan made their first contribution in https://github.com/dottxt-ai/outlines-core/pull/90 * @joennlae made their fLow12/2/2024
0.1.17## What's Changed * Remove failing MacOS 13 and add MacOS 15 build by @mgoin in https://github.com/dottxt-ai/outlines-core/pull/93 ## New Contributors * @mgoin made their first contribution in https://github.com/dottxt-ai/outlines-core/pull/93 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.16...0.1.17Low11/18/2024
0.1.16## What's Changed * Add statistical test for regex-guided generation by @dpsimpson in https://github.com/dottxt-ai/outlines-core/pull/77 * Add `Index`: PyO3 bindings to an index object by @kc611 in https://github.com/dottxt-ai/outlines-core/pull/78 * Generate rust coverage data by @torymur in https://github.com/dottxt-ai/outlines-core/pull/84 * :construction_worker: use latest cibuildwheel for py312, py313 wheels by @joerunde in https://github.com/dottxt-ai/outlines-core/pull/86 * `get_indeLow11/15/2024
0.1.15## What's Changed * Update clippy to run for all targets and with `python-bindings` feature by @umut-sahin in https://github.com/dottxt-ai/outlines-core/pull/61 * Support MacOS 13 and MacOS 14 builds by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/76 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.14...0.1.15Low10/15/2024
0.1.14## What's Changed * fix sdist archive set to v0.0.0 by @lapp0 in https://github.com/dottxt-ai/outlines-core/pull/72 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.13...0.1.14Low10/10/2024
0.1.13## What's Changed * Remove egg-info check by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/66 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.12...0.1.13Low10/10/2024
0.1.12## What's Changed * Update path to egg-info by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/65 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.11...0.1.12Low10/10/2024
0.1.11## What's Changed * Install setuptools-rust in PyPi release workflow by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/64 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.10...0.1.11Low10/10/2024
0.1.10## What's Changed * Remove `aarch64` from wheel build by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/62 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.9...0.1.10Low10/10/2024
0.1.9## What's Changed * Remove unused dependencies by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/54 * Fix silent `asv` failures by @brandonwillard in https://github.com/dottxt-ai/outlines-core/pull/58 * Add missing backslash to `maxProperties < 1` case for JSON object types by @brandonwillard in https://github.com/dottxt-ai/outlines-core/pull/59 * Remove user interface code by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/56 * Fix Wheel Build for `release_pypi.yaml` bLow10/10/2024
0.1.8## What's Changed * Remove `datasets` dependency by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/52 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.7...0.1.8Low10/9/2024
0.1.7**Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.5...0.1.7Low10/9/2024
0.1.6## What's Changed * Revert "Temporarily removing windows wheel building" by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/49 * Add installation prefix path for "Arrow" compilation by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/50 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.5...0.1.6Low10/9/2024
0.1.5## What's Changed * Temporarily removing windows wheel building by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/47 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.4...0.1.5Low10/9/2024
0.1.4## What's Changed * Skip musllinux 32-bit by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/46 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.3...0.1.4Low10/9/2024
0.1.3## What's Changed * Introduce `outlines_core.__version__` Attribute by @lapp0 in https://github.com/dottxt-ai/outlines-core/pull/45 ## New Contributors * @lapp0 made their first contribution in https://github.com/dottxt-ai/outlines-core/pull/45 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.2...0.1.3Low10/9/2024
0.1.2## What's Changed * Download the Rust compilers in manylinux by @rlouf in https://github.com/dottxt-ai/outlines-core/pull/44 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/compare/0.1.1...0.1.2Low10/8/2024
0.1.1## What's Changed * add cargo install as well by @ErikKaum in https://github.com/dottxt-ai/outlines-core/pull/39 * Refactor `RegexGuide` constructor interface by @brandonwillard in https://github.com/dottxt-ai/outlines-core/pull/40 * Create `prelude` module to manage imports by @umut-sahin in https://github.com/dottxt-ai/outlines-core/pull/43 **Full Changelog**: https://github.com/dottxt-ai/outlines-core/commits/0.1.1Low10/8/2024

Dependencies & License Audit

Loading dependencies...

Similar Packages

nvidia-cuda-cupti-cu12CUDA profiling tools runtime libs.12.9.79
pytorch-lightningPyTorch Lightning is the lightweight PyTorch wrapper for ML researchers. Scale your models. Write less boilerplate.2.6.6
tokenizersNo descriptionv0.23.2
xgrammarEfficient, Flexible and Portable Structured Generationv0.2.5.post1
apache-tvm-ffitvm ffiv0.1.13-post3

More in RAG & Memory

pytorch-lightningPyTorch Lightning is the lightweight PyTorch wrapper for ML researchers. Scale your models. Write less boilerplate.
banksA prompt programming language
opikDebug, evaluate, and monitor your LLM applications, RAG systems, and agentic workflows with comprehensive tracing, automated evaluations, and production-ready dashboards.
pdf_oxideThe fastest PDF library for Python and Rust. Text extraction, image extraction, markdown conversion, PDF creation & editing. 0.8ms mean, 5× faster than industry leaders, 100% pass rate on 3,830 PDFs.