Outlines lets Python callers pass an output type so model text is steered into valid JSON, literals, regex, grammars, or function-call shapes during generation.
Overview
Outlines is a Python library aimed at reliable structured generation from large language models. Instead of prompting for free text and repairing responses afterward, callers specify a target type or schema and Outlines constrains decoding so outputs match that structure as they are produced.
Integration paths cover remote APIs and local servers such as OpenAI-compatible clients, Ollama, vLLM, Transformers, llama.cpp, MLX-LM, SGLang, TGI, and related stacks. Examples in the documentation walk through support triage, categorization, document typing, partial event parsing with fallbacks, meeting extraction for function calling, and templated prompts.
Feature areas include literals and enums, Pydantic and JSON Schema outputs, regular expressions, context-free grammars, function-signature-driven calls, reusable Jinja templates, and packaged application helpers. The design stays low-level so it can sit beside existing LLM code without imposing an agent framework.
The project is maintained by dottxt, which also offers a hosted API for schema-compliant generation; the open-source library remains the core integration surface for in-process use.
Key features
- Type- or schema-guided generation
- JSON Schema and Pydantic models
- Regular expression constrained text
- Context-free grammar support
- Function signature calling
- Jinja prompt templates
- Multiple inference backend adapters
- Provider-swappable model clients
Use cases
- Support ticket field extraction
- Product description categorization
- Robust JSON from messy prompts
- Meeting detail function calls
- Few-shot templated classification