Home / Function/ _to_args_and_kwargs() — langchain Function Reference

_to_args_and_kwargs() — langchain Function Reference

Architecture documentation for the _to_args_and_kwargs() function in simple.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  a97adaea_b5f1_2906_9ae5_0d37c4c197bb["_to_args_and_kwargs()"]
  4ddde15c_138a_6971_91c4_325c8c3034dd["Tool"]
  a97adaea_b5f1_2906_9ae5_0d37c4c197bb -->|defined in| 4ddde15c_138a_6971_91c4_325c8c3034dd
  style a97adaea_b5f1_2906_9ae5_0d37c4c197bb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/tools/simple.py lines 72–97

    def _to_args_and_kwargs(
        self, tool_input: str | dict, tool_call_id: str | None
    ) -> tuple[tuple, dict]:
        """Convert tool input to Pydantic model.

        Args:
            tool_input: The input to the tool.
            tool_call_id: The ID of the tool call.

        Raises:
            ToolException: If the tool input is invalid.

        Returns:
            The Pydantic model args and kwargs.
        """
        args, kwargs = super()._to_args_and_kwargs(tool_input, tool_call_id)
        # For backwards compatibility. The tool must be run with a single input
        all_args = list(args) + list(kwargs.values())
        if len(all_args) != 1:
            msg = (
                f"""Too many arguments to single-input tool {self.name}.
                Consider using StructuredTool instead."""
                f" Args: {all_args}"
            )
            raise ToolException(msg)
        return tuple(all_args), {}

Subdomains

Frequently Asked Questions

What does _to_args_and_kwargs() do?
_to_args_and_kwargs() is a function in the langchain codebase, defined in libs/core/langchain_core/tools/simple.py.
Where is _to_args_and_kwargs() defined?
_to_args_and_kwargs() is defined in libs/core/langchain_core/tools/simple.py at line 72.

Analyze Your Own Codebase

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

Try Supermodel Free