Home / Function/ on_tool_error() — langchain Function Reference

on_tool_error() — langchain Function Reference

Architecture documentation for the on_tool_error() function in event_stream.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  cbfb1494_a541_4083_b9d5_c5f737190b70["on_tool_error()"]
  33d093c4_1ed0_fc6a_17c6_762d4c5cfa04["_AstreamEventsCallbackHandler"]
  cbfb1494_a541_4083_b9d5_c5f737190b70 -->|defined in| 33d093c4_1ed0_fc6a_17c6_762d4c5cfa04
  f3f30716_b889_9f3d_db23_c53fb64b7cf1["_get_tool_run_info_with_inputs()"]
  cbfb1494_a541_4083_b9d5_c5f737190b70 -->|calls| f3f30716_b889_9f3d_db23_c53fb64b7cf1
  9aed8e4f_9d4c_016f_aa43_c5908015cf8d["_get_parent_ids()"]
  cbfb1494_a541_4083_b9d5_c5f737190b70 -->|calls| 9aed8e4f_9d4c_016f_aa43_c5908015cf8d
  87f79bee_f9c5_8262_1829_62f633c4f870["_send()"]
  cbfb1494_a541_4083_b9d5_c5f737190b70 -->|calls| 87f79bee_f9c5_8262_1829_62f633c4f870
  style cbfb1494_a541_4083_b9d5_c5f737190b70 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/tracers/event_stream.py lines 698–728

    async def on_tool_error(
        self,
        error: BaseException,
        *,
        run_id: UUID,
        parent_run_id: UUID | None = None,
        tags: list[str] | None = None,
        **kwargs: Any,
    ) -> None:
        """Run when tool errors."""
        # Extract tool_call_id from kwargs if passed directly, or from run_info
        # (which was stored during on_tool_start) as a fallback
        tool_call_id = kwargs.get("tool_call_id")
        run_info, inputs = self._get_tool_run_info_with_inputs(run_id)
        if tool_call_id is None:
            tool_call_id = run_info.get("tool_call_id")

        event: StandardStreamEvent = {
            "event": "on_tool_error",
            "data": {
                "error": error,
                "input": inputs,
                "tool_call_id": tool_call_id,
            },
            "run_id": str(run_id),
            "name": run_info["name"],
            "tags": run_info["tags"],
            "metadata": run_info["metadata"],
            "parent_ids": self._get_parent_ids(run_id),
        }
        self._send(event, "tool")

Domain

Subdomains

Frequently Asked Questions

What does on_tool_error() do?
on_tool_error() is a function in the langchain codebase, defined in libs/core/langchain_core/tracers/event_stream.py.
Where is on_tool_error() defined?
on_tool_error() is defined in libs/core/langchain_core/tracers/event_stream.py at line 698.
What does on_tool_error() call?
on_tool_error() calls 3 function(s): _get_parent_ids, _get_tool_run_info_with_inputs, _send.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free