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

tool input must be an object

Error message

tool input must be an object

What it means

Error "tool input must be an object" thrown in rohitg00/ai-engineering-from-scratch.

Source

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

        unexpected = set(value) - set(properties)
        if unexpected and schema.get("additionalProperties") is False:
            raise ValueError(f"unexpected fields: {', '.join(sorted(unexpected))}")
        for name, item in value.items():
            if name in properties:
                _validate_schema_value(item, properties[name], f"{location}.{name}")


@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)

View on GitHub (pinned to 39ea8a1c6d)

When it happens

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