Favicon of Outlines

Outlines

An open-source Python library constrains LLM outputs to schemas and grammars, with local model support through Transformers and llama.cpp.

Screenshot of Outlines website

Outlines is a Python library for developers who need LLM responses in a defined format. It constrains generation to produce structured data for tasks such as extracting service tickets from emails or limiting an answer to allowed choices.

  • Typed and JSON outputs: Define responses with Python types, Pydantic models or JSON schemas so generated objects follow the required structure.
  • Text constraints: Use regular expressions and grammars to control formats that need rules beyond a JSON object.
  • Restricted choices and functions: Limit responses to predefined options or derive output structure from function signatures.
  • Model portability: Use a shared interface across supported model integrations, reducing changes to generation code when switching providers.

Outlines is open source under Apache 2.0. It supports local models through Transformers and llama.cpp, and model servers including Ollama and vLLM. API integrations include OpenAI, Gemini and Dottxt.

Where inference runs depends on the integration: local models run on your hardware, while cloud API integrations send requests to the chosen provider.

Similar to Outlines