{"record":{"id":"c159ab23ac84696f","repo":"rohitg00/ai-engineering-from-scratch","slug":"tool-use-id-is-required","errorCode":null,"errorMessage":"tool_use id is required","messagePattern":"tool_use id is required","errorType":"exception","errorClass":"ToolLoopError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py","lineNumber":206,"sourceCode":"    def validate(self, arguments: dict[str, Any]) -> None:\n        if not isinstance(arguments, dict):\n            raise ValueError(\"tool input must be an object\")\n        _validate_schema_value(arguments, self.input_schema, \"tool input\")\n\n\nclass ToolRegistry:\n    def __init__(self, tools: list[Tool]) -> None:\n        names = [tool.name for tool in tools]\n        if len(names) != len(set(names)):\n            raise ValueError(\"tool names must be unique\")\n        self._tools = {tool.name: tool for tool in tools}\n\n    def execute(self, block: dict[str, Any], approve: Callable[[Tool, dict[str, Any]], bool]) -> dict[str, Any]:\n        tool_id = block.get(\"id\")\n        name = block.get(\"name\")\n        arguments = block.get(\"input\")\n        if not isinstance(tool_id, str) or not tool_id:\n            raise ToolLoopError(\"tool_use id is required\")\n        result = {\"type\": \"tool_result\", \"tool_use_id\": tool_id}\n        tool = self._tools.get(name)\n        if tool is None:\n            return {**result, \"content\": f\"Unknown tool: {name}\", \"is_error\": True}\n        try:\n            tool.validate(arguments)\n            if tool.mutates and not approve(tool, arguments):\n                return {**result, \"content\": \"Approval denied\", \"is_error\": True}\n            value = tool.handler(arguments)\n            return {**result, \"content\": json.dumps(value, sort_keys=True)}\n        except Exception as exc:\n            return {**result, \"content\": f\"{type(exc).__name__}: {exc}\", \"is_error\": True}\n\n\nclass ScriptedModel:\n    def __init__(self, responses: list[dict[str, Any]]) -> None:\n        self.responses = copy.deepcopy(responses)\n        self.requests: list[list[dict[str, Any]]] = []","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py#L188-L224","documentation":"Error \"tool_use id is required\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:206 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}