Tool calling: let the model ask, keep your application in charge
An approachable guide to validating model-requested actions and returning useful results.

A tool call is a proposal
A model may suggest calling a function with arguments, but your application is responsible for deciding what actually runs. Think of the model as a planner, not as an authorization system. A request to look up an order and a request to refund one should never have the same level of trust.
Start with one narrow function
Define a small tool with a clear name, purpose and argument schema. A read-only search is a useful first example. Verify that your chosen model and endpoint support tool calling; their message shapes and capabilities may differ. Give the model enough context to decide when to call the function without exposing secrets in the prompt.
A tool should do one clear job, such as looking up an order status, instead of looking up, changing and notifying in one operation. Describe argument types, meanings and required fields. Validate missing and invalid values on the server even when a field is optional. Models can differ in how they handle tool definitions, so test with the model you intend to deploy.
A model can propose tools, while the application checks permission before execution.Validate before doing anything
Parse and validate every argument on the server. Check the signed-in user's permissions against the requested resource, enforce timeouts and limits, and require confirmation for sensitive side effects. Treat tool output as untrusted data too: a retrieved page can contain instructions that should not override your application rules.
A model proposing an order ID does not prove that the current user may view it. Your server must check the signed-in user, resource ownership and business rules; a tool call cannot bypass the application’s existing authorization. For deletion, payment, messaging or other side effects, show the concrete action and obtain appropriate confirmation before an auditable server-side operation.
Search results, pages, files and third-party responses can contain irrelevant or malicious instructions. Distinguish data from instructions and do not let external content override authorization or request secrets. Return only the information needed for the task, truncating or redacting when appropriate. Deterministic application code remains responsible for the final action.
Return a useful result and keep a trace
Send a concise tool result back in the format required by the endpoint, then let the model continue if the protocol supports that workflow. Record the tool name, outcome and a request identifier without logging credentials or unnecessary private data. Test invalid arguments, unavailable services and repeated calls, not just a perfect response.
A task may require several tool calls, but it must not run indefinitely. Set suitable timeouts, call limits and an overall deadline. Return an explicit failure when a service is unavailable, so the model or interface can choose the next step. Do not disguise failure as success or repeat costly or consequential actions without the user’s knowledge.
Test missing and invalid arguments, unauthorized resources, tool timeouts and duplicate calls, not only a successful lookup. Include a tool result containing malicious instructions and check that authorization remains unchanged. Record the tool name, outcome and request ID without full credentials, private conversations or unnecessary customer data. Sensitive actions need a confirmation step the model cannot bypass.
Treat model proposals as untrusted input
A tool name and arguments from a model are a proposal, not an authorization. Validate required fields, types, lengths and allowed values, and check whether the current user can access the requested resource. Never concatenate model output directly into SQL, shell commands or arbitrary URLs.
Keep tools focused. A read-only order lookup is easier to reason about than one tool that can look up, modify and refund an order. Enforce permissions on the server, not in the tool description. Treat text returned by web pages or external systems as untrusted data, and return only the fields needed for the current task.
Design for failures and human confirmation
Plan for timeouts, empty results, denied access and unavailable services. Return an honest failure to the model or user instead of inventing success. Limit retries on reads; for writes, messages and other side effects, establish how duplicate execution is prevented before trying again.
For consequential actions, show the exact operation and parameters for appropriate human confirmation, then enforce authorization on the server. A model saying that permission was granted is not evidence of consent. Log a request ID, tool name, outcome category and duration without routinely storing keys or sensitive customer records.
Start with one read-only tool
For an order-status assistant, first identify the signed-in user. The model may propose a lookup, but the server must verify that the order belongs to that user before returning a minimal status. If the order is missing or access is denied, the assistant should not guess.
Test a valid order, another user's order, missing and malformed IDs, a timeout and stale conversation context. Check that the final answer reflects the tool's actual result. Before adding a write-capable tool, test revoked confirmation, double clicks and uncertain outcomes; report an unknown state honestly rather than letting the model declare success.
Try a read-only lookup first
Imagine a tool that looks up an order by ID. Give it only the fields it needs, verify the current user owns the order on your server, and return a short status rather than the entire record. Then test a missing ID and an order belonging to someone else. If you later add a cancellation tool, require the appropriate confirmation before performing that separate action.
Before an important action, show the user the target, operation and likely effect. The server should then recheck authorization against the current state. Confirmation applies to that specific action; a model’s earlier natural-language response is not authorization. Report the actual success or failure so the user can decide what to do next.