LLM errors now also carry typed
AgentErrorKind classifications for more precise error handling. See LLM Error Classification for the complete taxonomy and failover decision system.Quick Start
1
Simple Agent with Structured Errors
2
Advanced Error Classification
Error Categories
The new classifier recognizes seven distinct error categories with specific recovery actions:Budget exhaustion (
BudgetExceededError) now routes to permanent and surfaces immediately without retries. It was previously reachable via rate_limit, which burned retry attempts on a billing state that will never recover on its own.How Errors Are Classified
The classifier picks a category using three signals, in order of precedence — stable signals first, message text last.- HTTP status code — read from
error.status_code,error.http_status,error.status, an integererror.code, orerror.response.status_code. - Exception class name — matched case-insensitively across the class hierarchy (MRO), so provider SDK subclasses are caught without importing those SDKs.
- Message regex — used only when steps 1 and 2 don’t match.
429 rate limit whose message never says “rate” is still classified as rate_limit.
Status code mapping
Exception class mapping
Provider SDK exception classes are matched by class name across the MRO, so subclasses in provider SDKs are handled without importing those SDKs.Ambiguous status codes (HTTP 400)
Some providers overload HTTP 400 — OpenAI returnscontext_length_exceeded as a 400, and some auth failures also come back as 400. The classifier refines a broad 400 using message signals before falling back to invalid_request.
Canonical examples live in the SDK tests:
tests/unit/llm/test_error_classifier.py::TestTypeAndCodeClassification and TestStructuredRetryAfter.LLMErrorClassification Structure
The new structured classification provides detailed recovery routing information:Provider-Aware Backoff
Different providers have different rate limiting patterns, so the classifier uses provider-specific base delays:
Backoff times include ±50% jitter to prevent thundering herd problems when multiple agents hit rate limits simultaneously.
Retry-After header
The classifier reads a provider’sRetry-After signal before falling back to message parsing, in this order:
error.response.headers["retry-after"](orRetry-After— case-insensitive)error.headers["retry-after"]error.retry_afterattribute- Regex over the message text
Retry-After) fall through to the regex step, so existing behaviour is preserved.
Recovery Actions
Jittered Backoff
The retry system uses exponential backoff with ±50% jitter to avoid thundering herd problems:Advanced Classification Usage
For users who want direct access to the classifier:How It Works
Async Support
Structured error classification works with both sync and async agents:Typed Error Classification (AgentErrorKind)
LLM errors are automatically classified into typedAgentErrorKind categories for precise handling. For the complete system, see LLM Error Classification.
Quick Reference
- Retryable:
rate_limit,overloaded,idle_timeout,auth - Non-retryable:
auth_permanent,model_not_found,format_error,context_overflow,billing - Limited retry:
unknown,empty_response
Legacy Support
The simple two-bucket classification (retryable/non-retryable) remains available for backward compatibility, but typed categories provide much more control.LLMError Structure
TheLLMError class provides structured error information:
Error Context
Theon_error handler receives enhanced context information:
Retry Depth Limits
The recursive recovery loop (after context compression and after transient-error backoff) is bounded by the agent’s configured retry policy:- With
retry=set: the loop honoursRetryBackoffConfig.max_retries(e.g.retry=True→ 3,max_retries=0→ recursion disabled). - Without
retry=set: the loop falls back to 2, preserving prior behaviour. - Context compression: triggered on the
context_overflowcategory.
This bound is read from
Agent._max_retry_depth(), which returns RetryBackoffConfig.max_retries when a retry config is present and 2 otherwise. See Agent Retry for how to configure it.Unimplemented Recovery Actions
Some recovery actions are planned but not yet implemented in the core system:Credential Rotation: When
should_rotate_credential=True, the user message includes “Credential rotation is not yet implemented”. Users must handle credential management manually.Model Fallback: When should_fallback_model=True, the user message includes “Model fallback is not yet implemented”. Users can implement custom fallback logic in their on_error handlers.Migration from Binary Classification
If you were previously checkingerror.is_retryable only, you can now access richer classification:
Before (binary classification):
Best Practices
Read error_category Instead of Regex Matching
Read error_category Instead of Regex Matching
Use the structured
error_category field instead of pattern matching on error messages:Monitor Structured Error Categories
Monitor Structured Error Categories
Track error patterns using the new categorical data:
Implement Custom Recovery Logic
Implement Custom Recovery Logic
Build on the structured classification for advanced recovery:
Provider-Specific Error Handling
Provider-Specific Error Handling
Customize handling based on the LLM provider:
Related
LLM Error Classification
Typed error categories and failover decisions
Task Retry Policy
Configure task-level retry behavior and policies
Hooks
Agent lifecycle hooks and events
Model Failover
Cross-provider failover with FailoverManager

