Skip to content

fix(core): make self positional-only in _run/_arun to allow "self" as tool input key#35043

Open
Varun Chawla (veeceey) wants to merge 2 commits intolangchain-ai:masterfrom
veeceey:fix/issue-34900-tool-self-param
Open

fix(core): make self positional-only in _run/_arun to allow "self" as tool input key#35043
Varun Chawla (veeceey) wants to merge 2 commits intolangchain-ai:masterfrom
veeceey:fix/issue-34900-tool-self-param

Conversation

@veeceey
Copy link
Contributor

@veeceey Varun Chawla (veeceey) commented Feb 6, 2026

Summary

  • Fixes BaseTool failing with TypeError: got multiple values for argument 'self' when tool input contains a key named "self" (e.g. tool.invoke({"self": 2}))
  • Adds the positional-only parameter marker (/) after self in _run and _arun across BaseTool, StructuredTool, and Tool, so Python routes user-supplied "self" into **kwargs instead of conflicting with the method receiver
  • Adds sync and async regression tests

Closes #34900

Test plan

  • New unit test test_tool_invoke_with_self_keyword_in_input verifies sync invocation with "self" in input
  • New unit test test_tool_ainvoke_with_self_keyword_in_input verifies async invocation with "self" in input
  • Full existing test suite passes (157 passed, 4 skipped) with no regressions

Review notes

The change is minimal -- just adding / after self in the method signatures. This is a non-breaking change: all existing subclass overrides of _run/_arun continue to work exactly as before. The positional-only marker only affects whether Python allows self=... as a keyword argument at the call site; it does not change how the method is dispatched or overridden.

Note that user-defined BaseTool subclasses that override _run without self, / will still hit this issue if they receive "self" as a keyword argument. However, the built-in tool classes (StructuredTool, Tool) and the @tool decorator -- which cover the vast majority of usage -- are all fixed.

@github-actions github-actions bot added external core `langchain-core` package issues & PRs fix For PRs that implement a fix and removed external labels Feb 6, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 6, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 13 untouched benchmarks
⏩ 23 skipped benchmarks1


Comparing veeceey:fix/issue-34900-tool-self-param (809e0a1) with master (5624001)2

Open in CodSpeed

Footnotes

  1. 23 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on master (4a632cf) during the generation of this report, so 5624001 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@veeceey
Copy link
Contributor Author

Manual test results

Ran tests/unit_tests/test_tools.py from libs/core on branch fix/issue-34900-tool-self-param (Python 3.14):

Targeted tests (-k "self"):

tests/unit_tests/test_tools.py::test_tool_invoke_with_self_keyword_in_input PASSED
tests/unit_tests/test_tools.py::test_tool_ainvoke_with_self_keyword_in_input PASSED

Full test_tools.py suite (regression check):

157 passed, 4 skipped, 254 warnings in 0.35s

No failures, no regressions. The positional-only self fix works as expected — tools with a "self" input key can now be invoked without hitting TypeError: _run() got multiple values for argument 'self'.

@veeceey Varun Chawla (veeceey) force-pushed the fix/issue-34900-tool-self-param branch from cff4401 to a0b8fac Compare February 6, 2026 20:35
@veeceey
Copy link
Contributor Author

All tests passing, ready for review/merge

@veeceey
Copy link
Contributor Author

Hi maintainers, friendly ping on this PR. It's been open a few days now and all checks are passing. Would appreciate it whenever you get a chance to review. Thank you for your time!

@github-actions github-actions bot added fix For PRs that implement a fix and removed fix For PRs that implement a fix labels Feb 13, 2026
@veeceey
Copy link
Contributor Author

Quick ping -- this one's been green for a while now. Happy to address any feedback if needed. Thanks for your time!

@github-actions github-actions bot added the size: S 50-199 LOC label Mar 9, 2026
@veeceey Varun Chawla (veeceey) force-pushed the fix/issue-34900-tool-self-param branch 2 times, most recently from e6a9285 to 9c560b8 Compare March 12, 2026 04:29
…lf" as tool input key

When a tool is invoked with input containing a key named "self" (e.g.
`tool.invoke({"self": 2})`), the keyword argument collides with the
bound method receiver, raising `TypeError: got multiple values for
argument 'self'`.

Adding the positional-only marker (`/`) after `self` in `_run` and
`_arun` across `BaseTool`, `StructuredTool`, and `Tool` lets Python
route user-supplied `"self"` into `**kwargs` instead of conflicting
with the method's own receiver.

Closes langchain-ai#34900
@veeceey Varun Chawla (veeceey) force-pushed the fix/issue-34900-tool-self-param branch from 9c560b8 to af81693 Compare March 13, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core `langchain-core` package issues & PRs external fix For PRs that implement a fix size: S 50-199 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant