rohitg00/ai-engineering-from-scratch · error · ValueError
tool names must be unique
Error message
tool names must be unique
What it means
Error "tool names must be unique" thrown in rohitg00/ai-engineering-from-scratch.
Source
Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:198
@dataclass(frozen=True)
class Tool:
name: str
description: str
input_schema: dict[str, Any]
handler: Callable[[dict[str, Any]], Any]
mutates: bool = False
def validate(self, arguments: dict[str, Any]) -> None:
if not isinstance(arguments, dict):
raise ValueError("tool input must be an object")
_validate_schema_value(arguments, self.input_schema, "tool input")
class ToolRegistry:
def __init__(self, tools: list[Tool]) -> None:
names = [tool.name for tool in tools]
if len(names) != len(set(names)):
raise ValueError("tool names must be unique")
self._tools = {tool.name: tool for tool in tools}
def execute(self, block: dict[str, Any], approve: Callable[[Tool, dict[str, Any]], bool]) -> dict[str, Any]:
tool_id = block.get("id")
name = block.get("name")
arguments = block.get("input")
if not isinstance(tool_id, str) or not tool_id:
raise ToolLoopError("tool_use id is required")
result = {"type": "tool_result", "tool_use_id": tool_id}
tool = self._tools.get(name)
if tool is None:
return {**result, "content": f"Unknown tool: {name}", "is_error": True}
try:
tool.validate(arguments)
if tool.mutates and not approve(tool, arguments):
return {**result, "content": "Approval denied", "is_error": True}
value = tool.handler(arguments)
return {**result, "content": json.dumps(value, sort_keys=True)}View on GitHub (pinned to 39ea8a1c6d)
When it happens
Trigger: Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:198 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26).
Data as JSON: /api/errors/cf4d5507544fcd81.
Report an issue: GitHub.