Post body (copy/paste)
Context
I’m following up on an earlier GitHub issue:
- Original issue: More robust error handling for nodes · Issue #6170 · langchain-ai/langgraph · GitHub
- Node-level handler implementation: feat(langgraph): add node-level error handlers by longquanzheng · Pull Request #7233 · langchain-ai/langgraph · GitHub
The node-level error_handler from #7233 solved the original problem and has already helped me a lot.
What still feels missing
I’m now hitting a separate ergonomics gap in larger graphs.
When many nodes should share the same recovery behavior, setting error_handler node-by-node becomes repetitive. I can do it, but it adds a lot of boilerplate.
What I already understand exists
I know run-level callbacks can observe graph success/failure and update external systems.
That helps for “always update backend run status on success/error,” but it doesn’t solve in-graph recovery behavior where I want fallback logic that can receive NodeError and return Command / state
updates.
Proposal
Would it make sense to add a graph-wide default error handler for StateGraph, used only when a node does not define its own error_handler?
Example API shape:
builder = StateGraph(State)
builder.set_default_error_handler(handler)
## Desired precedence
1. Node-level error_handler (if present)
2. Graph-level default error handler
3. Current failure propagation
## Desired semantics (non-breaking)
- Runs after retries are exhausted
- interrupt() behavior stays unchanged
- Handler receives NodeError
- Handler may return Command
- If the handler raises, error propagates as today
## Non-goals
- Not overriding explicit node handlers
- Not changing retry semantics
- Not introducing breaking changes
## Why this helps in practice
In background-job workflows, many nodes need the same failure fallback (for example, write failure metadata and route cleanly), while a few nodes still need custom handlers. A graph-wide fallback would
reduce repeated config significantly while preserving current behavior.
If this direction makes sense, I’m happy to contribute the implementation.