Home / Function/ default_tool_parser() — langchain Function Reference

default_tool_parser() — langchain Function Reference

Architecture documentation for the default_tool_parser() function in tool.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c3cea370_0eb2_ed10_0436_0c051020ac26["default_tool_parser()"]
  210f83c5_4be3_e20e_b877_98a194178520["tool.py"]
  c3cea370_0eb2_ed10_0436_0c051020ac26 -->|defined in| 210f83c5_4be3_e20e_b877_98a194178520
  64f5f480_21f9_a113_f62b_7946632322d5["tool_call()"]
  c3cea370_0eb2_ed10_0436_0c051020ac26 -->|calls| 64f5f480_21f9_a113_f62b_7946632322d5
  dd2af7a2_3844_b2a2_ba90_dddf83f5646f["invalid_tool_call()"]
  c3cea370_0eb2_ed10_0436_0c051020ac26 -->|calls| dd2af7a2_3844_b2a2_ba90_dddf83f5646f
  style c3cea370_0eb2_ed10_0436_0c051020ac26 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/messages/tool.py lines 349–383

def default_tool_parser(
    raw_tool_calls: list[dict],
) -> tuple[list[ToolCall], list[InvalidToolCall]]:
    """Best-effort parsing of tools.

    Args:
        raw_tool_calls: List of raw tool call dicts to parse.

    Returns:
        A list of tool calls and invalid tool calls.
    """
    tool_calls = []
    invalid_tool_calls = []
    for raw_tool_call in raw_tool_calls:
        if "function" not in raw_tool_call:
            continue
        function_name = raw_tool_call["function"]["name"]
        try:
            function_args = json.loads(raw_tool_call["function"]["arguments"])
            parsed = tool_call(
                name=function_name or "",
                args=function_args or {},
                id=raw_tool_call.get("id"),
            )
            tool_calls.append(parsed)
        except json.JSONDecodeError:
            invalid_tool_calls.append(
                invalid_tool_call(
                    name=function_name,
                    args=raw_tool_call["function"]["arguments"],
                    id=raw_tool_call.get("id"),
                    error=None,
                )
            )
    return tool_calls, invalid_tool_calls

Subdomains

Frequently Asked Questions

What does default_tool_parser() do?
default_tool_parser() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/tool.py.
Where is default_tool_parser() defined?
default_tool_parser() is defined in libs/core/langchain_core/messages/tool.py at line 349.
What does default_tool_parser() call?
default_tool_parser() calls 2 function(s): invalid_tool_call, tool_call.

Analyze Your Own Codebase

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

Try Supermodel Free