mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-13 13:17:52 +02:00
feat(prebuilt): add support for handle_tool_errors with single exception type (#6021)
This PR extends the `ToolNode` `handle_tool_errors` property to also
accept a single exception type: `type[Exception]`.
Example:
```python
tool_node_with_error_handling = ToolNode(
[tool1, tool2, tool3], handle_tool_errors=ValueError
).invoke(...)
"""A tool node that will only retry a failed tool call if a ValueError is raised"""
```
This commit is contained in:
@@ -274,10 +274,12 @@ async def test_tool_node_error_handling() -> None:
|
||||
|
||||
# test catching all exceptions, via:
|
||||
# - handle_tool_errors = True
|
||||
# - passing a single exception
|
||||
# - passing a tuple of all exceptions
|
||||
# - passing a callable with all exceptions in the signature
|
||||
for handle_tool_errors in (
|
||||
True,
|
||||
Exception,
|
||||
(ValueError, ToolException, ToolInvocationError),
|
||||
handle_all,
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user