This is an early release preview. You may encounter bugs.
Outlines logo
Unclaimed

Tool coding

Outlines

Constrained decoding library forcing LLM output to match a JSON Schema, regex or grammar.

A+ 94/100 GitHub score ? This grade is derived from GitHub signals, not user votes. Open for the full breakdown.
No votes yet

01 / About

What Outlines is.

Outlines constrains a language model's output during generation so the result matches a declared structure, rather than repairing the text afterwards with parsing or regular expressions. You pass the desired output type alongside the prompt — model(prompt, output_type) — and generation is restricted to values of that type.

The type vocabulary mirrors Python's own: Literal[...] for a fixed set of choices, int and other basic types for scalars, Pydantic models for nested objects, a function signature for function-calling parameters, a regular expression for pattern-shaped text, and a context-free grammar for more complex structures. Union types allow a fallback branch, such as returning structured data or the string "I don't know" when a document lacks the fields.

The same code runs across model backends, so the model can be swapped without changing the calling code. Utility features include Jinja-based prompt templates loaded from a string or a file, custom types, and applications that package a template and an output type into a callable function.

Model type Supported through
Server vLLM, Ollama
Local transformers, llama.cpp
API OpenAI, Gemini, Dottxt

Features

  • Multiple choices: constrain output to a predefined set of options
  • JSON and Pydantic: generate output matching a JSON Schema or Pydantic model
  • Function calls: infer the required structure from a function signature and return matching parameters
  • Regular expressions: generate text that follows a regex pattern
  • Grammars: enforce structures described by a context-free grammar
  • Provider independence: the same calling code runs against server, local, and API model backends
  • Prompt templates: Jinja templates kept separate from code, loaded from a string or a file, including few-shot examples
  • Applications: package a template and an output type together as a reusable function

02 / Discussion CREDIBILITY-GATED

Discussion

Reading is open to everyone. Posting and voting need a verified identity or a GitHub grade of B or higher.

  • No discussions yet.

03 / Build

Build with Outlines.

Browse the catalogue for frameworks, tools, and harnesses, each scored on real GitHub credibility.

Get Outlines →

Browse the catalogue