rohitg00/ai-engineering-from-scratch · error · ToolLoopError
response content must be a list
Error message
response content must be a list
What it means
Error "response content must be a list" thrown in rohitg00/ai-engineering-from-scratch.
Source
Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:252
def __init__(
self,
model: ScriptedModel,
registry: ToolRegistry,
approve: Callable[[Tool, dict[str, Any]], bool] = lambda _tool, _args: False,
max_turns: int = 8,
) -> None:
self.model = model
self.registry = registry
self.approve = approve
self.max_turns = max_turns
def run(self, request: str) -> tuple[str, list[dict[str, Any]]]:
messages: list[dict[str, Any]] = [{"role": "user", "content": request}]
for _ in range(self.max_turns):
response = self.model.create(messages)
blocks = response.get("content")
if not isinstance(blocks, list):
raise ToolLoopError("response content must be a list")
messages.append({"role": "assistant", "content": copy.deepcopy(blocks)})
reason = response.get("stop_reason")
if reason == "end_turn":
text = "".join(block.get("text", "") for block in blocks if block.get("type") == "text")
return text, messages
if reason != "tool_use":
raise ToolLoopError(f"unsupported stop reason: {reason}")
calls = [block for block in blocks if block.get("type") == "tool_use"]
if not calls:
raise ToolLoopError("tool_use stop without calls")
results = [self.registry.execute(block, self.approve) for block in calls]
messages.append({"role": "user", "content": results})
raise ToolLoopError("maximum turns exceeded")
def demo() -> tuple[str, list[dict[str, Any]]]:
add = Tool(
"add",View on GitHub (pinned to 39ea8a1c6d)
When it happens
Trigger: Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:252 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/4fe0688e00cc600f.
Report an issue: GitHub.