fix(prebuilt): handle plain ToolException in default tool error handler#6959
Open
Balaji Seshadri (gitbalaji) wants to merge 1 commit intolangchain-ai:mainfrom
Open
Conversation
d832605 to
067c89d
Compare
_default_handle_tool_errors only caught ToolInvocationError (a subclass of ToolException). A plain ToolException — as raised by MCP adapters and other tool wrappers — was re-raised instead of being returned as an error ToolMessage, crashing the graph. Fix: check isinstance(e, ToolException) instead of ToolInvocationError. Since ToolInvocationError calls super().__init__(self.message), str(e) is equivalent to e.message for both types, so no behaviour changes for the existing ToolInvocationError path. Fixes langchain-ai#6449. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
067c89d to
3ce743c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6449.
_default_handle_tool_errorsonly caughtToolInvocationError(a subclass ofToolException). A plainToolException— as raised by MCP adapters (langchain_mcp_adapters) and other tool wrappers — was re-raised instead of being returned as an errorToolMessage, crashing the graph.Before:
After:
ToolInvocationErrorcallssuper().__init__(self.message), sostr(e)is identical toe.message— no behaviour change for the existing path.Test plan
test_tool_node_default_handler_catches_tool_exception— verifies a plainToolExceptionfrom an async tool is returned as an errorToolMessagewith the default handlertest_tool_node_error_handlingandtest_tool_node_handle_tool_errors_falsestill passmake format— cleanmake lint— clean (Success: no issues found in 5 source files)🤖 Generated with Claude Code