outlines-cascade
Structured LLM generation with cascading failover.
Combine Outlines' structured generation with llm-pycascade's cascading failover — enforce structured output (Pydantic, JSON Schema, regex, CFG, choice) across a fallback chain of LLM providers, with a metadata-enriched result object.
Features
- Full structured output — Pydantic models, JSON Schema,
Literal/choice, regex, context-free grammars - Cascade failover — ordered provider chain; if one fails, the next is tried immediately
- Circuit breaking — exponential backoff cooldowns (30s → 3600s) with
Retry-Aftersupport - Smart type routing — regex/CFG requests auto-skip cloud APIs and route to local models
- Streaming — incremental text chunks via async generators
- Batch — process multiple prompts with shared adapter cache
- 7 providers — OpenAI, Anthropic, Gemini, Ollama, SGLang, Transformers, LlamaCpp
- Async-native — built on
asynciothroughout
Installation
pip install outlines-cascade
With provider support:
pip install "outlines-cascade[openai,anthropic,db]"
Quick Start
Single generation
import asyncio
from typing import Literal
from pydantic import BaseModel
from outlines_cascade import generate, CascadeEntry
class Sentiment(BaseModel):
label: Literal["positive", "negative", "neutral"]
confidence: float
async def main():
result = await generate(
prompt="I love this product!",
output_type=Sentiment,
entries=[
CascadeEntry(provider="openai", model="gpt-4o"),
CascadeEntry(provider="anthropic", model="claude-sonnet-4-20250514"),
],
)
print(result.value) # Sentiment(label="positive", confidence=0.95)
print(result.provider) # "openai"
print(result.attempts) # [CascadeAttempt(...)]
asyncio.run(main())
Streaming
from outlines_cascade import stream, StreamChunk, StructuredResponse
async for item in stream(prompt="...", output_type=Sentiment, entries=[...]):
if isinstance(item, StreamChunk) and not item.done:
print(item.text, end="", flush=True)
elif isinstance(item, StructuredResponse):
print(f"\nProvider: {item.provider}")
Batch
from outlines_cascade import batch
results = await batch(
prompts=["review 1", "review 2"],
output_type=Sentiment,
entries=[...],
)
for r in results:
print(r.response.value if r.response else r.error)
Config-driven (TOML)
from outlines_cascade import generate, load_config
config = load_config("~/.config/outlines-cascade/config.toml")
result = await generate(prompt="...", output_type=Sentiment, config=config, cascade_name="primary")
See config.example.toml for the full format.
Type Routing
Cloud APIs (OpenAI, Anthropic, Gemini) only support JSON Schema. Local models and SGLang support all types via FSM-based constrained decoding:
| Type | Cloud | Local / SGLang |
|---|---|---|
| Pydantic / JSON Schema | ✅ | ✅ |
Literal / choice |
✅ | ✅ |
| Regex | ❌ skipped | ✅ |
| CFG | ❌ skipped | ✅ |
When you request a regex with a mixed cascade, cloud entries are silently skipped and the request routes to the local model automatically.
Providers
| Provider | Type | Supports |
|---|---|---|
| OpenAI | cloud | JSON Schema, Choice |
| Anthropic | cloud | JSON Schema, Choice |
| Gemini | cloud | JSON Schema, Choice |
| Ollama | cloud | JSON Schema, Choice |
| SGLang | steerable | All (JSON, regex, CFG) |
| Transformers | steerable | All (FSM) |
| LlamaCpp | steerable | All (FSM) |
Documentation
- Quick Start
- User Guide — type routing, cascade patterns, cooldowns
- Configuration — TOML format reference
- API Reference — all public classes and functions
- Provider Reference — provider setup and capabilities
- Examples — runnable demos
Dependencies
- Outlines
>=1.0— structured generation - llm-pycascade
>=0.1.0— cascade failover - Pydantic
>=2.0— data validation
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file outlines_cascade-0.1.1.tar.gz.
File metadata
- Download URL: outlines_cascade-0.1.1.tar.gz
- Upload date:
- Size: 195.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7091d2a51ac3373999626b3ae96c406dbe7bb39cfcca2a57be9b4c36fc04f358
|
|
| MD5 |
f6484f61a415b87c177a991e33739bb9
|
|
| BLAKE2b-256 |
e59ba159bc28d3c778e7502f45a290f401807d08f260bc62e886a5ea8835767f
|
Provenance
The following attestation bundles were made for outlines_cascade-0.1.1.tar.gz:
Publisher:
python-publish.yml on paluigi/outlines-cascade
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
outlines_cascade-0.1.1.tar.gz -
Subject digest:
7091d2a51ac3373999626b3ae96c406dbe7bb39cfcca2a57be9b4c36fc04f358 - Sigstore transparency entry: 2214873911
- Sigstore integration time:
-
Permalink:
paluigi/outlines-cascade@69ba629f3a5b9f4fc4bf272b745ba779a0ee5823 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/paluigi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@69ba629f3a5b9f4fc4bf272b745ba779a0ee5823 -
Trigger Event:
release
-
Statement type:
File details
Details for the file outlines_cascade-0.1.1-py3-none-any.whl.
File metadata
- Download URL: outlines_cascade-0.1.1-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b17d12240cca85156e92b9cc85fd24b3f05b6712f198476d0683ae6c4a89775
|
|
| MD5 |
bd86a5ab7b0825d1845fe44ecadc3788
|
|
| BLAKE2b-256 |
179012855770715bf61aea8a51292c70eef9a5755bee8cc7c27f62c73a25b570
|
Provenance
The following attestation bundles were made for outlines_cascade-0.1.1-py3-none-any.whl:
Publisher:
python-publish.yml on paluigi/outlines-cascade
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
outlines_cascade-0.1.1-py3-none-any.whl -
Subject digest:
5b17d12240cca85156e92b9cc85fd24b3f05b6712f198476d0683ae6c4a89775 - Sigstore transparency entry: 2214873934
- Sigstore integration time:
-
Permalink:
paluigi/outlines-cascade@69ba629f3a5b9f4fc4bf272b745ba779a0ee5823 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/paluigi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@69ba629f3a5b9f4fc4bf272b745ba779a0ee5823 -
Trigger Event:
release
-
Statement type: