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

unsupported tool

Error message

unsupported tool

What it means

Raised in ToolRegistry.call when the requested tool name is not one of the registered read-only or approval-gated tools (lookup_order, issue_refund). This is a fail-closed capability guard: unknown tool names can never execute against the order store.

Solutions

  1. Fix the tool name in the model's tool call (typos, casing)
  2. Register the new tool in the registry and its LeastPrivilegeGate rule before exposing it
  3. Catch and return a structured tool error to the model so it can self-correct
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at certifications/claude/lessons/30-developer-application-capstone/code/main.py:151 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/00ddb595521dadbe. Report an issue: GitHub.

Appendix: source

Thrown at certifications/claude/lessons/30-developer-application-capstone/code/main.py:151

        }


class LeastPrivilegeGate:
    def allow(self, tool: str, arguments: dict[str, Any], approved: bool = False) -> tuple[bool, str]:
        if tool == "lookup_order" and set(arguments) == {"order_id"}:
            return True, "read-only lookup"
        if tool == "issue_refund":
            return (approved, "explicit approval required" if not approved else "approved refund")
        return False, "capability or arguments not allowlisted"


class ToolRegistry:
    def __init__(self, orders: dict[str, str]) -> None:
        self.orders = dict(orders)

    def call(self, tool: str, arguments: dict[str, Any]) -> dict[str, Any]:
        if tool != "lookup_order":
            raise ValueError("unsupported tool")
        order_id = arguments["order_id"]
        if order_id not in self.orders:
            return {"found": False, "order_id": order_id}
        return {"found": True, "order_id": order_id, "status": self.orders[order_id]}


class SupportAgent:
    def __init__(self, registry: ToolRegistry, gate: LeastPrivilegeGate | None = None) -> None:
        self.registry = registry
        self.gate = gate or LeastPrivilegeGate()

    def run(self, request: str) -> SupportResult:
        trace: list[TraceEvent] = [TraceEvent("request_received", {"length": len(request)})]
        injection_markers = ("ignore previous", "reveal secret", "read .env", "bypass approval")
        if any(marker in request.lower() for marker in injection_markers):
            trace.append(TraceEvent("policy_denial", {"reason": "instruction injection marker"}))
            return SupportResult("denied", "I cannot follow instructions that bypass policy or request secrets.", None, True, tuple(trace))

View on GitHub (pinned to 39ea8a1c6d)