Outlines
Guaranteed structured generation from LLMs: enforce JSON, regex, grammar, or Pydantic schemas at the token level.
Outlines
Outlines (by dottxt-ai) makes LLM outputs reliably structured by constraining token sampling to only produce valid JSON, regex patterns, context-free grammars, or Pydantic model instances — with zero retry loops. The constraint is applied at the logit level, so it is mathematically impossible for the model to produce invalid output.
Key Features
- JSON schema enforcement — pass a Pydantic model or JSON schema; get a perfectly valid object every time
- Regex-guided generation — constrain output to any regular expression pattern
- Grammar-based — EBNF context-free grammars for generating valid code, SQL, or custom DSLs
- Choice constraints — force the model to pick from a fixed set of options
- Model-agnostic — works with transformers, llama.cpp (via llama-cpp-python), and vLLM
- No retries — unlike post-hoc JSON parsers, invalid tokens are literally impossible
Quick Start
pip install outlines
import outlines
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
city: str
model = outlines.models.transformers("Qwen/Qwen2.5-0.5B-Instruct")
generator = outlines.generate.json(model, Person)
person = generator("Generate a fictional person.")
print(person) # Person(name='Alice', age=30, city='Paris')
Install via ai-supply
npx ai-supply add outlines-structured-generation
Curated mirror of the open-source Outlines project (Apache-2.0). Install upstream from the repository.
Compromise signals — malicious or tampered code (leaked secrets, backdoors, a dropped executable) — reduce the score, and known dependency CVEs carry a bounded penalty (they warrant review but never QUARANTINE — update the dependency to clear). Other dangerous-by-capability traits are risk surface, expected for some capabilities. Every finding is mapped to its OWASP control below.
Findings mapped to the OWASP Top 10 for LLM Applications (2025) and the OWASP Machine Learning Security Top 10. Expand any flagged control for the exact findings — compromise reduces the score; expected/risk-surface do not, except a known CVE, which carries a small bounded penalty (high/critical → Review).
The same gate an agent runs before installing (POST /api/v1/trust/outlines-structured-generation/check). Click a policy:
Consume Outlines programmatically. Authenticate with an API key or session — see Authorize an agent.
# Agents: CHECK BEFORE YOU INSTALL (no auth) — score, grade, level, capability manifest
curl https://ai-supply.store/api/v1/trust/outlines-structured-generation
# Gate against your org policy (returns { pass, violations })
curl -X POST https://ai-supply.store/api/v1/trust/outlines-structured-generation/check \
-H "Content-Type: application/json" \
-d '{"minGrade":"B","denyPermissions":["shell"],"denyUnknownEgress":true}'
# CLI
npx ai-supply add outlines-structured-generation
# REST (install → download)
curl -X POST https://ai-supply.store/api/v1/listings/outlines-structured-generation/install \
-H "Authorization: Bearer $AIM_KEY"
# MCP tool
install_listing({ "slug": "outlines-structured-generation" })OpenAPI spec →Curated mirror — latest upstream source. See the repository for tagged releases.