AI Foundations for Developers COURSE·LESSON 27 OF 410 completed

Tool Calls and Authorization

The model proposes; your application executes

A tool call is structured output requesting a function and arguments. The model does not inherently gain direct access to your database. Your application receives the proposal, validates it, checks permissions, invokes the tool, and returns an appropriate result.

For “When did I buy Acorn Pro?”, the model might propose get_purchase. The application already knows the authenticated user's account. It should bind the account server-side rather than allowing the model to choose an arbitrary customer identifier.

Rendering diagram…
flowchart TD
  A[User request] --> B[Model proposes tool call]
  B --> C[Validate name and arguments]
  C --> D[Check authenticated permissions]
  D --> E[Execute bounded tool]
  E --> F[Return minimal result]
  F --> G[Model drafts answer]

A safer execution contract

text
PSEUDOCODE
allowed_tools = {get_my_purchase, get_current_policy}
proposal = model.generate(request, tool_descriptions)
reject if proposal.name is not in allowed_tools
arguments = validate_schema(proposal.arguments)
account = authenticated_session.account
authorize(account, proposal.name)
result = execute(proposal.name, account=account, **arguments)
return_to_model(redact_and_limit(result))

This is architecture pseudocode; it is not a vendor SDK example. Tool schemas need clear names, required arguments, and documented errors. Tools should return enough information for the task without exposing unrelated records.

Reads and writes have different consequences

A policy lookup is a read. Issuing a refund is a write that changes business state. Consequential writes need explicit user intent and, where appropriate, confirmation. The confirmation must describe the actual action and target. Recheck authorization when executing, not only when proposing.

Use idempotency keys for retryable writes so a timeout does not trigger duplicate refunds. Define timeouts, maximum result sizes, allowed domains, and retry budgets. A tool response is untrusted input too: a retrieved webpage can contain instructions attempting to steer the model.

Checkpoint with answers

Can a tool description saying “only access this user's data” replace code-level authorization? No.

What should happen when the model requests an unknown function? Reject it, report the allowed behavior safely, and record the contract failure.

Exercise: A payment call times out after the provider accepted it. Is blindly retrying safe? Answer: no. Use an idempotency contract or check action status before another execution.

Learn at your own pace0 / 41 lessons complete