dottxt-ai /outlines

Structured Outputs

★ 16,011⑂ 917👁 55⑃ 1,004● 910▤ 90
PythonApache-2.0Created 2023-03-17dottxt-ai.github.io/outlines/
下载:Outlines v1.3.3Outlines-1.3.3 ↓1.3.32026-08-06
+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(tempe

Top issues

Discussions

Latest release

Outlines v1.3.3 1.3.3 2026-08-06
What'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

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON