Skip to main content

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-After support
  • 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 asyncio throughout

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

Dependencies

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

outlines_cascade-0.1.1.tar.gz (195.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

outlines_cascade-0.1.1-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

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

Hashes for outlines_cascade-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7091d2a51ac3373999626b3ae96c406dbe7bb39cfcca2a57be9b4c36fc04f358
MD5 f6484f61a415b87c177a991e33739bb9
BLAKE2b-256 e59ba159bc28d3c778e7502f45a290f401807d08f260bc62e886a5ea8835767f

See more details on using hashes here.

Provenance

The following attestation bundles were made for outlines_cascade-0.1.1.tar.gz:

Publisher: python-publish.yml on paluigi/outlines-cascade

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file outlines_cascade-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for outlines_cascade-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5b17d12240cca85156e92b9cc85fd24b3f05b6712f198476d0683ae6c4a89775
MD5 bd86a5ab7b0825d1845fe44ecadc3788
BLAKE2b-256 179012855770715bf61aea8a51292c70eef9a5755bee8cc7c27f62c73a25b570

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page