rohitg00/ai-engineering-from-scratch · error · ToolLoopError

tool_use id is required

Error message

tool_use id is required

What it means

Error "tool_use id is required" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:206

    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)}
        except Exception as exc:
            return {**result, "content": f"{type(exc).__name__}: {exc}", "is_error": True}


class ScriptedModel:
    def __init__(self, responses: list[dict[str, Any]]) -> None:
        self.responses = copy.deepcopy(responses)
        self.requests: list[list[dict[str, Any]]] = []

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:206 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/c159ab23ac84696f. Report an issue: GitHub.