AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

StructuredTool Fails When Input Contains 'Self' Key Due To Parameter Collision In _Run

StructuredTool and other BaseTool subclasses fail when invoked with a keyword argument named 'self' because the internal _run method's first parameter is also named 'self', causing a duplicate argument error.

highConfidence 95%Langchain-CoreRetrieversAgentslangchain-coreAffected V1.2.7

Origin Analysis

In BaseTool.run, user inputs are passed as keyword arguments to self._run. Since _run is an instance method with the first parameter named `self`, any user input key 'self' collides with the bound method's self parameter, leading to TypeError.
1. Define a function that accepts arbitrary keyword arguments: def func(**kwargs): return f'{kwargs}'. 2. Create a StructuredTool with that function and an args_schema that allows extra keys. 3. Invoke the tool with a dict containing a 'self' key and another key: tool.invoke({'self': 2, 'other': 3}). 4. Observe TypeError: StructuredTool._run() got multiple values for argument 'self'.

Fixing Code Block

Edge Case Audit

This monkey-patch only fixes StructuredTool; other tool classes that inherit from BaseTool and define `_run(self, ...)` may still have the same issue. If the internal logic of `_run` changes in future versions, this patch may need updating. Rollback by removing the monkey-patch or reverting the source change.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state