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.0.tar.gz (194.4 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.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file outlines_cascade-0.1.0.tar.gz.

File metadata

  • Download URL: outlines_cascade-0.1.0.tar.gz
  • Upload date:
  • Size: 194.4 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.0.tar.gz
Algorithm Hash digest
SHA256 10901db6a7c1bac67c88e7a3db60e52b196188311de601977d8e0e641eb30cce
MD5 3721d9825f7109791116393f55453580
BLAKE2b-256 8e192698c66a43414ab2f8ccf192afc427390222d38cfb743ab8a446e4c0c06b

See more details on using hashes here.

Provenance

The following attestation bundles were made for outlines_cascade-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for outlines_cascade-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82dd84668b7f2a94f44d3d3ce6c03f9745bfeb4ff40e54b1710ec2fcf3276831
MD5 f1b722969c9ece880e54bb02a827f315
BLAKE2b-256 da0b8d992c79b3b5d84beaf6aca16be422f15d802c793ff5ace72f7d9ae57ef0

See more details on using hashes here.

Provenance

The following attestation bundles were made for outlines_cascade-0.1.0-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

0.1.1

2 files

This release

0.1.0 This release

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