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
Metadata
Release files for outlines-cascade 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| outlines_cascade-0.1.1.tar.gz | 195.3 kB | With provenance | Details for outlines_cascade-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| outlines_cascade-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for outlines_cascade-0.1.1-py3-none-any.whl |
Total release size: 218.6 kB
Release files / outlines_cascade-0.1.1.tar.gz
| Download URL | outlines_cascade-0.1.1.tar.gz |
|---|---|
| Size | 195.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7091d2a51ac3373999626b3ae96c406dbe7bb39cfcca2a57be9b4c36fc04f358
|
|
BLAKE2b-256 checksum How to use checksums |
e59ba159bc28d3c778e7502f45a290f401807d08f260bc62e886a5ea8835767f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 21, 2026.
Transparency logRelease files / outlines_cascade-0.1.1-py3-none-any.whl
| Download URL | outlines_cascade-0.1.1-py3-none-any.whl |
|---|---|
| Size | 23.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5b17d12240cca85156e92b9cc85fd24b3f05b6712f198476d0683ae6c4a89775
|
|
BLAKE2b-256 checksum How to use checksums |
179012855770715bf61aea8a51292c70eef9a5755bee8cc7c27f62c73a25b570
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 21, 2026.
Transparency logSecurity for outlines-cascade 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for outlines_cascade-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.