Advanced10 min
RetryPolicy, Error Taxonomy & CachePolicy
Structured error handling in LangGraph: RetryPolicy for transient failures, error taxonomy for routing errors to the right handler, and CachePolicy for avoiding redundant computation.
Quick Reference
- →RetryPolicy on nodes: max_attempts, retry_on, initial_interval, backoff_factor for transient errors
- →Error taxonomy: transient → RetryPolicy, LLM-recoverable → loop back, user-fixable → interrupt(), unexpected → bubble up
- →CachePolicy on @task: TTL-based caching to avoid recomputing identical operations
- →InMemoryCache or custom cache backends for persistent caching across runs
- →RetryPolicy works on both graph nodes (add_node) and @task decorators
- →Combine all three for production-grade error handling
RetryPolicy on Nodes
Adding retry policies to graph nodes
| Parameter | Type | Default | Purpose |
|---|---|---|---|
| max_attempts | int | 3 | Total attempts including the first try |
| initial_interval | float | 1.0 | Seconds to wait before first retry |
| backoff_factor | float | 2.0 | Multiply interval by this each retry |
| retry_on | tuple[Exception] | All exceptions | Only retry on these exception types |
| jitter | bool | True | Add random jitter to prevent thundering herd |