exceptions
Outlines exception hierarchy and per-provider normalization.
All public exceptions inherit from APIError → OutlinesError → Exception.
Use :func:normalize_provider_exception to convert a raw provider SDK exception
into the appropriate Outlines type.
APIConnectionError
APIError
Bases: OutlinesError
Base class for all provider API errors raised by Outlines.
Subclasses map to specific HTTP status codes or failure categories (see the hierarchy below). Catch this class to handle any provider error generically, or catch a subclass for finer-grained control.
Attributes:
| Name | Type | Description |
|---|---|---|
provider |
str | None
|
Short provider name, e.g. |
original_exception |
Exception | None
|
The raw SDK exception that was caught, preserved for debugging. |
status_code |
int | None
|
HTTP status code, if one could be extracted from the exception. |
request_id |
str | None
|
Provider request ID extracted from the exception or response headers, useful when filing bug reports with a provider. |
retryable |
bool
|
|
hint |
str
|
Short human-readable suggestion. On Python 3.11+ this is attached via
|
Source code in outlines/exceptions.py
APITimeoutError
AuthenticationError
BadRequestError
Bases: APIError
400, 409, 413, 422, other 4xx - malformed request.
Source code in outlines/exceptions.py
GenerationError
NotFoundError
PermissionDeniedError
ProviderResponseError
RateLimitError
ServerError
is_provider_exception(exc, provider)
Return True only for provider/transport exceptions we expect to normalize.
This prevents programmer errors (TypeError, AttributeError, etc.)
from being silently re-labeled as APIError.
- If the exception matches the provider's explicit SDK map → True.
- If the exception carries an HTTP status code → True (covers SDK base
classes not listed individually, e.g.
ollama.ResponseError). - Otherwise → False (let it propagate as-is).
Source code in outlines/exceptions.py
normalize_provider_errors(provider)
Normalize provider exceptions raised inside this block.
This is a context manager instead of a decorator so wrappers can use the same helper around sync calls, awaited async calls, sync generators, async generators, and other provider SDK control-flow shapes without needing separate wrapper machinery for each function kind.
Source code in outlines/exceptions.py
normalize_provider_exception(exc, provider)
Map a provider SDK exception to the appropriate Outlines exception.
- Try the provider's SDK exception map (most-specific-first via isinstance).
- Fall back to status-code inspection on the original exception.
- Default to generic APIError.