Skip to content

fix(tools): raise clear error for duplicate tool names in tool_runner#1535

Open
Zawwarsami16 wants to merge 1 commit into
anthropics:mainfrom
Zawwarsami16:fix/tool-runner-duplicate-name-error
Open

fix(tools): raise clear error for duplicate tool names in tool_runner#1535
Zawwarsami16 wants to merge 1 commit into
anthropics:mainfrom
Zawwarsami16:fix/tool-runner-duplicate-name-error

Conversation

@Zawwarsami16
Copy link
Copy Markdown

@Zawwarsami16 Zawwarsami16 commented May 13, 2026

I was poking around tool_runner and noticed that the runner accepts duplicate tool names without complaining. If you pass two tools that happen to share a name (say, two different get_weather impls imported from different modules), the second silently overwrites the first in _tools_by_name = {tool.name: tool for tool in tools}, and your first tool is gone before the request is even built. The API would reject the duplicate, but only with a generic 400 after the round trip, and by then you have no idea which side of your code was wrong.

This patch adds an upfront check in BaseToolRunner.__init__ that walks the tools, collects any names that show up more than once, and raises a ValueError listing them. It runs before any HTTP work, so you get the error at the call site of tool_runner(...) instead of inside a request handler. Behaviour for unique names is unchanged. I left the _tools_by_name dict comprehension in place and just added the validation pass above it.

Three new tests in tests/lib/tools/test_runners.py cover the sync runner, the async runner, and the case where multiple distinct names each have duplicates (the error should list all of them). uv run pytest tests/lib/ -n auto reports 496 passed, 1 skipped, 1 xfailed, and uv run ruff check . && uv run pyright && uv run mypy . are clean.

@Zawwarsami16 Zawwarsami16 requested a review from a team as a code owner May 13, 2026 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant