Favicon of Outlines

Outlines

An open-source Python library that constrains LLM outputs to schemas and grammars, with support for local backends including Ollama and llama.cpp.

Screenshot of Outlines website

Outlines is an open-source Python library for developers who need LLM responses to match a defined structure. It constrains output during generation, reducing the need to repair malformed JSON or retry responses that don't fit an application's requirements. The library uses the Apache 2.0 license.

It works with local LLM backends including llama.cpp, Transformers and MLX-LM, as well as servers such as Ollama, vLLM, SGLang and TGI. It also connects to cloud providers including OpenAI, Anthropic and Gemini. Where inference runs depends on the backend you choose: local integrations run models on your hardware, while cloud integrations send requests to the selected provider. Dottxt offers a separate hosted API for structured generation without running your own models.

Output definitions can use Python types and Pydantic models, or express constraints through JSON Schema, regular expressions and context-free grammars. These cover tasks such as extracting a service ticket from a customer email, restricting a response to predefined choices, or generating an object with required fields. Outlines can also infer output structure from function signatures.

Its shared interface lets developers switch model providers without rewriting the surrounding generation code. It doesn't require an agent framework. For repeated requests, Outlines compiles constraints once rather than compiling them again for each generation.

Similar to Outlines