Skip to content

BaseTool cannot handle unbound functions with a "self" parameter. #34900

@andreitava-uip

Description

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-perplexity
  • langchain-prompty
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Reproduction Steps / Example Code (Python)

from langchain_core.tools import StructuredTool


def func(**kwargs) -> str:
    return f"{kwargs}"


tool = StructuredTool(
    name="test_tool",
    func=func,
    args_schema={
        "type": "object",
        "properties": {},
    },
)

tool_input = {
    "self": 2,
    "other": 3,
}

# while unconventional, our function is perfectly valid
result = func(**tool_input)
print("Result of func:", result)  # works

result = tool.invoke(tool_input)
# TypeError: StructuredTool._run() got multiple values for argument 'self'

Error Message and Stack Trace (if applicable)

Result of func: {'self': 2, 'other': 3}
Traceback (most recent call last):
  File "/home/andrei/python-sdks/coded-playground/.stuffs/test4.py", line 29, in <module>
    result = tool.invoke(tool_input)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andrei/python-sdks/coded-playground/.venv/lib/python3.11/site-packages/langchain_core/tools/base.py", line 632, in invoke
    return self.run(tool_input, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andrei/python-sdks/coded-playground/.venv/lib/python3.11/site-packages/langchain_core/tools/base.py", line 987, in run
    raise error_to_raise
  File "/home/andrei/python-sdks/coded-playground/.venv/lib/python3.11/site-packages/langchain_core/tools/base.py", line 953, in run
    response = context.run(self._run, *tool_args, **tool_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: StructuredTool._run() got multiple values for argument 'self'

Description

I have defined a function that accepts any arguments by keyword.
If I define a StructuredTool based on this function (or decorate it with @tool) and try to invoke it with a payload containing self, it will fail.
I expect that a function which normally works with a payload, should work with the same payload when invoked as a tool.

This seems to be due to BaseTool._run() getting the unpacked kwargs, which leads to multiple values for self (one the bound object, the other an intended parameter)

While this looks a bit unconventional (and if explicitly defining the parameters, it is), it can be relevant when the args_schema is externally defined and the function is supposed to generically handle a payload.

System Info

System Information

OS: Linux
OS Version: #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025
Python Version: 3.11.14 (main, Oct 14 2025, 21:26:53) [Clang 20.1.4 ]

Package Information

langchain_core: 1.2.7
langchain: 1.2.7
langsmith: 0.4.59
langchain_anthropic: 1.3.1
langgraph_sdk: 0.3.0

Optional packages not installed

langserve

Other Dependencies

anthropic: 0.76.0
httpx: 0.28.1
jsonpatch: 1.33
langgraph: 1.0.7
orjson: 3.11.5
packaging: 25.0
pydantic: 2.12.5
pyyaml: 6.0.3
requests: 2.32.5
requests-toolbelt: 1.0.0
tenacity: 9.1.2
typing-extensions: 4.15.0
uuid-utils: 0.12.0
zstandard: 0.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRelated to a bug, vulnerability, unexpected error with an existing featurecore`langchain-core` package issues & PRsexternal

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions