LangGraph/Control Flow
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
ParameterTypeDefaultPurpose
max_attemptsint3Total attempts including the first try
initial_intervalfloat1.0Seconds to wait before first retry
backoff_factorfloat2.0Multiply interval by this each retry
retry_ontuple[Exception]All exceptionsOnly retry on these exception types
jitterboolTrueAdd random jitter to prevent thundering herd