PythiloLesson 7 of 12 · progress kept in this browser

Practice in Lab: Authorize a tool call outside the model →

Authorize a tool call outside the model

A model's request to call a tool is a proposal, not authorization. A trusted executor must check the tool name, tenant scope and granted permissions before any effect. Document text or model arguments cannot enlarge the caller's authority.

The exercise uses an explicit policy table and returns a decision without performing an external action. This keeps policy tests deterministic. Production execution should also validate argument schemas, bind object-level authorization to actual resources, apply idempotency where needed and record an audit trail. A prompt saying that a user approved something is not an approval record.

policy={"read":{"scope":"docs:read"}}
granted={"docs:read"}
print(policy["read"]["scope"] in granted)
Your task

Implement tool_allowed(call,tenant,scopes,policy). call has tool,tenant. policy maps tool->required scope. Return True only for a known tool, matching tenant and granted required scope; missing fields fail closed.