--- id: outlines-core version: "0.2.14" license: Apache-2.0 license_treatment: permissive maintenance: active --- # outlines-core — Structured Text Generation in Rust License: permissive · Maintenance: active · Downloads: 5.3M/mo ## 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 above — 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 pip install outlines-core uv add outlines-core 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_current - Install friction: medium - Maintenance: active - Downloads: 5.3M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags json schema to regex for llm, structured generation language models, constrained token sampling, finite state machine token guidance, schema-guided text generation, structured-generation, constraint-guided-decoding, rust-bindings [View on SkillFed](https://skillfed.io/packages/outlines-core) · [View on PyPI](https://pypi.org/project/outlines-core/)