_handle_tool_error() — langchain Function Reference
Architecture documentation for the _handle_tool_error() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5674464e_53c8_8ac6_8d4a_eca7e0803115["_handle_tool_error()"] 80cebff4_efbd_4311_85e9_de0dc81a7eee["base.py"] 5674464e_53c8_8ac6_8d4a_eca7e0803115 -->|defined in| 80cebff4_efbd_4311_85e9_de0dc81a7eee 51b059af_20e0_9233_077d_cd590dd94dc8["run()"] 51b059af_20e0_9233_077d_cd590dd94dc8 -->|calls| 5674464e_53c8_8ac6_8d4a_eca7e0803115 c2f33b98_e5b2_c424_d7d3_8cbd05da78d1["arun()"] c2f33b98_e5b2_c424_d7d3_8cbd05da78d1 -->|calls| 5674464e_53c8_8ac6_8d4a_eca7e0803115 style 5674464e_53c8_8ac6_8d4a_eca7e0803115 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/tools/base.py lines 1181–1210
def _handle_tool_error(
e: ToolException,
*,
flag: Literal[True] | str | Callable[[ToolException], str] | None,
) -> str:
"""Handle tool execution errors based on the configured flag.
Args:
e: The tool exception that occurred.
flag: How to handle the error (`bool`, `str`, or `Callable`).
Returns:
The error message to return.
Raises:
ValueError: If the flag type is unexpected.
"""
if isinstance(flag, bool):
content = e.args[0] if e.args else "Tool execution error"
elif isinstance(flag, str):
content = flag
elif callable(flag):
content = flag(e)
else:
msg = (
f"Got unexpected type of `handle_tool_error`. Expected bool, str "
f"or callable. Received: {flag}"
)
raise ValueError(msg) # noqa: TRY004
return content
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does _handle_tool_error() do?
_handle_tool_error() is a function in the langchain codebase, defined in libs/core/langchain_core/tools/base.py.
Where is _handle_tool_error() defined?
_handle_tool_error() is defined in libs/core/langchain_core/tools/base.py at line 1181.
What calls _handle_tool_error()?
_handle_tool_error() is called by 2 function(s): arun, run.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free