+1
日增长
+10
周增长
+88
月增长
16,011
stars
917
forks
55
watchers
1,004
prs
910
issues
90
releases
README
🗒️ Structured outputs for LLMs 🗒️
Made with ❤👷️ by the team at .txt
Trusted by NVIDIA, Cohere, HuggingFace, vLLM, etc.
[![PyPI Version][pypi-version-badge]][pypi]
[![Downloads][downloads-badge]][pypistats]
[![Stars][stars-badge]][stars]
[![Discord][discord-badge]][discord]
[![Blog][dottxt-blog-badge]][dottxt-blog]
[![Twitter][twitter-badge]][twitter]
The .txt API is currently in early access. Request access here →
🚀 Building the future of structured generation
We're working with select partners to develop new interfaces to structured generation.
Need XML, FHIR, custom schemas or grammars? Let's talk.
Audit your schema: share one schema, we show you what breaks under generation, the constraints that fix it, and compliance rates before and after. Sign up here.
Table of Contents
- Why Outlines?
- Quickstart
- Real-World Examples
- 🙋♂️ Customer Support Triage
- 📦 E-commerce Product Categorization
- 📊 Parse Event Details with Incomplete Data
- 🗂️ Categorize Documents into Predefined Types
- 📅 Schedule a Meeting with Function Calling
- 📝 Dynamically Generate Prompts with Re-usable Templates
- They Use Outlines
- Model Integrations
- Core Features
- Other Features
- About .txt
- Community
Why Outlines?
LLMs are powerful but their outputs are unpredictable. Most solutions attempt to fix bad outputs after generation using parsing, regex, or fragile code that breaks easily.
Outlines guarantees structured outputs during generation — directly from any LLM.
- Works with any model - Same code runs across OpenAI, Ollama, vLLM, and more
- Simple integration - Just pass your desired output type: model(prompt, output_type)
- Guaranteed valid structure - No more parsing headaches or broken JSON
- Provider independence - Switch models without changing code
The Outlines Philosophy
Outlines follows a simple pattern that mirrors Python's own type system. Simply specify the desired output type, and Outlines will ensure your data matches that structure exactly:
- For a yes/no response, use Literal["Yes", "No"]
- For numerical values, use int
- For complex objects, define a structure with a Pydantic model
Quickstart
Getting started with outlines is simple:
1. Install outlines
shell
pip install outlines
2. Connect to your preferred model
python
import outlines
from transformers import AutoTokenizer, AutoModelForCausalLM
MODEL_NAME = "microsoft/Phi-3-mini-4k-instruct"
model = outlines.from_transformers(
AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map="auto"),
AutoTokenizer.from_pretrained(MODEL_NAME)
)
3. Start with simple structured outputs
python
from typing import Literal
from pydantic import BaseModel
Simple classification
sentiment = model(
"Analyze: 'This product completely changed my life!'",
Literal["Positive", "Negative", "Neutral"]
)
print(sentiment) "Positive"
Extract specific types
temperature = model("What's the boiling point of water in Celsius?", int)
print(tempeTop issues
#479Add probability distribution to choices22 comments · 2023-12-24#1351Slow performance with the latest outlines + latest (or previous than latest vllm)17 comments · 2024-12-30#1407Token-triggered processors11 comments · 2025-02-07#1962Built-in Regex terms are not JSON-quoted inside containers (list[types.email] generates [[email protected]])9 comments · 2026-07-25#1376Make `generate.json` compatible with OpenAI's function calling format8 comments · 2025-01-14#1110llama_cpp - JSON fails to generate when using Pydantic model with models.llama_cpp8 comments · 2024-08-21#1742Widen asset format supports7 comments · 2025-08-29#1233context-free grammars example does not work with vLLM integration 7 comments · 2024-10-28
Discussions
#2101mcp-slim: Inlining JSON Schema $ref/$defs and compacting MCP tool schemas by 50%-98% for structured tool calling0 comments · 2026-11-12#2052Is the constrained-vs-unconstrained gap much wider on abliterated checkpoints?0 comments · 2026-09-26#2028[Show and Tell / RFC] Finite-Horizon Reachability Masking (GCLM) for Guaranteed Goal/Syntax Completion in O(1) Time0 comments · 2026-08-30#1860External audit step after constrained generation of DSL expressions6 comments · 2026-05-04#1858Should we have dedicated models for providers that are OpenAI-compatible?1 comments · 2026-05-04#1837promptdiff — lint and quality scoring for LLM prompts3 comments · 2026-03-26#1836Functions/Classes with different names than the documentation and/or missing in the package2 comments · 2026-03-25#1824Using Outlines for constrained decoding over large Knowledge Bases3 comments · 2026-03-06
Latest release
Outlines v1.3.3 1.3.3 2026-08-06What's Changed Support PEP 604 unions (int | str) as output types by @sohumt123 in https://github.com/dottxt-ai/outlines/pull/1932 fix: reject negative counts in exactly/at_least/at_most/between by @chuenchen309 in https://github.com/dottxt-ai/outlines/pull/1922 fix: raise clearly instead of asserting on a rejected XGrammar token by @chuenchen309 in https://github.com/dottxt-ai/outlines/pull/1923 fix(models): handle nullable object type (list form) in additionalProperties pass by @ErenAta16 in https://github.com/dottxt-ai/outlines/pull/1918 fix: reject leading-zero octets in the ipv4