{"record":{"id":"4fe0688e00cc600f","repo":"rohitg00/ai-engineering-from-scratch","slug":"response-content-must-be-a-list","errorCode":null,"errorMessage":"response content must be a list","messagePattern":"response content must be a list","errorType":"exception","errorClass":"ToolLoopError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py","lineNumber":252,"sourceCode":"    def __init__(\n        self,\n        model: ScriptedModel,\n        registry: ToolRegistry,\n        approve: Callable[[Tool, dict[str, Any]], bool] = lambda _tool, _args: False,\n        max_turns: int = 8,\n    ) -> None:\n        self.model = model\n        self.registry = registry\n        self.approve = approve\n        self.max_turns = max_turns\n\n    def run(self, request: str) -> tuple[str, list[dict[str, Any]]]:\n        messages: list[dict[str, Any]] = [{\"role\": \"user\", \"content\": request}]\n        for _ in range(self.max_turns):\n            response = self.model.create(messages)\n            blocks = response.get(\"content\")\n            if not isinstance(blocks, list):\n                raise ToolLoopError(\"response content must be a list\")\n            messages.append({\"role\": \"assistant\", \"content\": copy.deepcopy(blocks)})\n            reason = response.get(\"stop_reason\")\n            if reason == \"end_turn\":\n                text = \"\".join(block.get(\"text\", \"\") for block in blocks if block.get(\"type\") == \"text\")\n                return text, messages\n            if reason != \"tool_use\":\n                raise ToolLoopError(f\"unsupported stop reason: {reason}\")\n            calls = [block for block in blocks if block.get(\"type\") == \"tool_use\"]\n            if not calls:\n                raise ToolLoopError(\"tool_use stop without calls\")\n            results = [self.registry.execute(block, self.approve) for block in calls]\n            messages.append({\"role\": \"user\", \"content\": results})\n        raise ToolLoopError(\"maximum turns exceeded\")\n\n\ndef demo() -> tuple[str, list[dict[str, Any]]]:\n    add = Tool(\n        \"add\",","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py#L234-L270","documentation":"Error \"response content must be a list\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:252 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"}