Skip to content
← Tools / Skills
ToolDottxt (.txt)/10 trustVerified
Outlines logo

Outlines

Structured text generation — guide any LLM's output with types, regex, and grammars

Visit official site →

About

Outlines is a Python library for structured generation: instead of fixing bad LLM output after the fact with parsing and regex, it constrains generation itself so outputs are valid by construction. You declare the desired shape — a Literal for multiple choice, a Pydantic model / dataclass / TypedDict for JSON, a regex pattern, or a context-free grammar — and Outlines enforces it at the logits level for local models (OutlinesLogitsProcessor plugs straight into HuggingFace transformers) or via provider structured-output support for APIs. It ships model adapters for transformers, llama.cpp, vLLM, Ollama, OpenAI, Gemini, and Dottxt's own API, plus prompt templates and applications that bundle templates with output types. Built by Dottxt (.txt); the library is Apache-2.0 open source with a commercial API tier alongside it.

What it can do

  • • Logits-level structured generation: regex patterns, JSON schemas, context-free grammars, and multiple-choice constraints enforced during decoding
  • • Model adapters: HuggingFace transformers, llama.cpp, vLLM, Ollama, OpenAI, Gemini, and Dottxt APIs — same code across providers
  • • `OutlinesLogitsProcessor` for injecting constraints into existing transformers pipelines
  • • Prompt templates (including file-based few-shot templates) and applications that bundle templates with output types
  • • Function-calling support by inferring structure from function signatures

Setup

  1. Install: pip install outlines (extras available, e.g. pip install "outlines[transformers]" which pulls transformers, datasets, and torch).
  2. Pick your model adapter: local via outlines.models.transformers("microsoft/Phi-3-mini-4k-instruct", device="cuda") (or pass a pre-loaded HF model + tokenizer), server via vLLM/Ollama adapters, or API via outlines.from_gemini(genai.Client(), "gemini-1.5-flash-latest") / OpenAI.
  3. Choose an output type: Literal["Yes", "No"] for multiple choice, a Pydantic class for JSON, a regex string, or a grammar.
  4. Generate: result = model("Pizza or burger?", PizzaOrBurger) — the returned text is guaranteed to match the declared structure.
  5. (Alternative) Drop OutlinesLogitsProcessor into your own HuggingFace generate() call to apply constraints without the Outlines model wrapper.

Prerequisites

Python; for local models a matching backend (transformers + torch, llama.cpp, vLLM, or Ollama); for API models the relevant provider SDK and API key (e.g. google-genai, OpenAI).

Use cases

datacode

Works with

Generic APIAny agent (.md)

Trust score — 9/10

/10 trustVerified

Scored 9/10 (verified tier, metrics-v1). Evidence: 15,923 GitHub stars (log-scaled vs catalog peers); blended with ~1,278,852 monthly package downloads; last push 21d ago; 12 releases/12mo; 194 open issues. Manual review: Dottxt commercial API pricing unverified. License: Apache-2.0.

★ 15,923 GitHub stars

How the trust score is built

Full methodology →
Adoption · stars/downloads, log-scaled vs peers
8.2/10
Maintenance · recency, releases, issue load
9.0/10
Openness · license + docs
10.0/10
Manual review · sanity read + red-flag check
9.0/10
  • · 15,923 GitHub stars (log-scaled vs catalog peers)
  • · blended with ~1,278,852 monthly package downloads
  • · last push 21d ago; 12 releases/12mo; 194 open issues
  • · manual review: Dottxt commercial API pricing unverified

Sources

Every fact above was checked against these sources. Where a claim comes from the provider and couldn't be independently verified, the text says so.