Skip to content

The agent engineering platform.

chore(langchain_v1): tool error exceptions (#33424)

Eugene Yurtsev75965474fce3
diff --git a/libs/langchain_v1/langchain/tools/__init__.py b/libs/langchain_v1/langchain/tools/__init__.py
index 8f1fa554f5..e413550dbe 100644
--- a/libs/langchain_v1/langchain/tools/__init__.py
+++ b/libs/langchain_v1/langchain/tools/__init__.py
@@ -8,11 +8,7 @@ from langchain_core.tools import (
tool,
)
-from langchain.tools.tool_node import (
- InjectedState,
- InjectedStore,
- ToolNode,
-)
+from langchain.tools.tool_node import InjectedState, InjectedStore, ToolInvocationError, ToolNode
__all__ = [
"BaseTool",
@@ -21,6 +17,7 @@ __all__ = [
"InjectedToolArg",
"InjectedToolCallId",
"ToolException",
+ "ToolInvocationError",
"ToolNode",
"tool",
]
diff --git a/libs/langchain_v1/langchain/tools/tool_node.py b/libs/langchain_v1/langchain/tools/tool_node.py
index fc00fd6b40..cb58cd6266 100644
--- a/libs/langchain_v1/langchain/tools/tool_node.py
+++ b/libs/langchain_v1/langchain/tools/tool_node.py
@@ -72,6 +72,7 @@ from langchain_core.tools import BaseTool, InjectedToolArg
from langchain_core.tools import tool as create_tool
from langchain_core.tools.base import (
TOOL_MESSAGE_BLOCK_TYPES,
+ ToolException,
get_all_basemodel_annotations,
)
from langgraph._internal._runnable import RunnableCallable
@@ -239,8 +240,11 @@ def msg_content_output(output: Any) -> str | list[dict]:
return str(output)
-class ToolInvocationError(Exception):
- """Exception raised when a tool invocation fails due to invalid arguments."""
+class ToolInvocationError(ToolException):
+ """An error occurred while invoking a tool due to invalid arguments.
+
+ This exception is only raised when invoking a tool using the ToolNode!
+ """
def __init__(
self, tool_name: str, source: ValidationError, tool_kwargs: dict[str, Any]
diff --git a/libs/langchain_v1/tests/unit_tests/tools/test_imports.py b/libs/langchain_v1/tests/unit_tests/tools/test_imports.py
index 79c7371e12..b629d8a825 100644
--- a/libs/langchain_v1/tests/unit_tests/tools/test_imports.py
+++ b/libs/langchain_v1/tests/unit_tests/tools/test_imports.py
@@ -7,6 +7,7 @@ EXPECTED_ALL = {
"InjectedToolArg",
"InjectedToolCallId",
"ToolException",
+ "ToolInvocationError",
"ToolNode",
"tool",
}