Safe LLM tool calling starts with a narrow contract, not a clever prompt. This checklist explains how to design tool schemas, validate model-generated arguments, restrict permissions, handle failures, request human approval, and record results so an AI agent can take useful actions without becoming an uncontrolled API client.
Overview
LLM tool calling, also called function calling, allows a model to select an operation and return structured arguments for your application to execute. The model should not receive direct authority over your systems. Your application remains the control plane: it selects the available tools, validates the arguments, checks authorization, applies business rules, performs the action, and sends a controlled result back to the model.
A reliable design separates four concerns:
- Intent: What action is the user asking for?
- Contract: What exact arguments does the tool accept?
- Authorization: Is this user, workflow, or service allowed to perform the action?
- Execution: What happens when the action succeeds, fails, times out, or needs approval?
This separation matters because a valid JSON object is not necessarily a safe request. A model may produce syntactically correct arguments that refer to the wrong account, exceed a permitted limit, expose sensitive data, or trigger an irreversible operation. Schema validation is therefore one layer of defense, not the complete security model.
Keep the first version of each tool small. A tool that performs one clearly named operation is easier to test and authorize than a general-purpose endpoint with many modes. For related implementation practices, compare this checklist with the AI agent tool design checklist and the LLM application release checklist.
A reusable tool-definition template
Use a definition that describes purpose, arguments, constraints, and operational risk. Adapt the exact wrapper to the provider SDK you use; provider tool-calling syntax and supported schema features can change.
{
"name": "create_support_ticket",
"description": "Create a support ticket for an authenticated customer. Use only when the user explicitly asks to open a ticket.",
"parameters": {
"type": "object",
"properties": {
"subject": { "type": "string", "minLength": 1, "maxLength": 120 },
"summary": { "type": "string", "minLength": 1, "maxLength": 4000 },
"priority": { "type": "string", "enum": ["low", "normal", "high"] }
},
"required": ["subject", "summary"],
"additionalProperties": false
},
"execution": {
"approval": "required_for_high_priority",
"authorization": "customer_scope_only",
"idempotency": "required"
}
}
The execution object is illustrative application metadata; it may not belong in the provider-facing schema. Keep these controls in your own tool registry even if the model never sees them.
Checklist by scenario
When naming and scoping a new tool
- Use a specific verb and object, such as
get_invoice_statusorcreate_calendar_event, rather thanmanage_data. - Define one business action per tool. Avoid a single tool with a free-form operation name and unrestricted payload.
- State when the tool should be used and when it should not be used.
- Distinguish read operations from write, delete, send, publish, or transfer operations.
- Document whether the action is reversible, idempotent, delayed, or externally visible.
- Set an explicit maximum for text, list length, numeric values, and page size.
When designing the argument schema
Prefer constrained fields over open-ended strings. Use enumerations for known choices, strict formats for identifiers and dates, and separate fields for separate concepts. For example, do not ask the model to place a recipient, subject, and message inside one free-form payload field.
| Schema approach | Best use | Main risk |
|---|---|---|
| Enum values | Fixed states such as priority or sort order | Values become stale when business rules change |
| Strict object | Transactional actions with known fields | Requires deliberate versioning for changes |
| Array of objects | Batch reads or bounded line items | Large or duplicate batches can increase cost and execution risk |
| Free-form text | Human-readable content such as a ticket summary | May contain instructions, secrets, or unsupported claims |
| Union of modes | A small set of genuinely different request types | Complex validation and ambiguous model selection |
Use strict object behavior where the provider supports it, but still validate the parsed result in your application. Provider support for JSON Schema features, structured outputs, argument limits, and strictness varies, so treat the provider documentation and your integration tests as the source of truth.
When validating and authorizing a call
- Parse the tool call as JSON and reject malformed data.
- Validate the schema, including required fields, types, ranges, formats, and unknown properties.
- Normalize values, such as trimming whitespace or canonicalizing an identifier, without changing the user’s intended target.
- Resolve sensitive context on the server. Do not rely on the model to supply the current user ID, organization ID, role, or account scope.
- Check authorization against the authenticated principal and the resolved resource.
- Apply business limits, such as maximum amount, record count, recipient count, or execution frequency.
- Require an idempotency key for operations that might be retried.
A useful rule is that the model may propose what to do, but the server decides whether it may be done. This is especially important for tools that update records, send messages, change access, run SQL, or call third-party services. For natural-language database workflows, see the safe natural-language-to-SQL workflow.
When an action needs human approval
Introduce approval before execution when an action is irreversible, externally visible, financially consequential, privacy-sensitive, or unusual for the user. The approval screen should show the normalized action, target, important parameters, expected effect, and any uncertainty. Avoid displaying only the model’s original prose.
- Pause the workflow with a durable approval record.
- Bind approval to a specific tool name, argument hash, user, and expiration time.
- Reject execution if the arguments change after approval.
- Record who approved the action and which policy permitted it.
- Provide a clear cancel and retry path.
For low-risk read tools, approval may be unnecessary. For high-risk writes, consider a two-step pattern: first prepare a proposed change, then request approval, then execute the approved change through a separate tool.
When a call fails
Return a small, structured error to the model and keep internal details in server logs. Distinguish validation errors, authorization failures, temporary dependency failures, timeouts, and completed-but-uncertain outcomes. Retry only failures that are demonstrably safe to retry, using bounded attempts and idempotency protection.
A tool result should tell the model what it can do next without exposing secrets or raw stack traces. For example: {"status":"validation_error","field":"priority","message":"Use low, normal, or high."}. If an external request may have completed before a timeout, do not blindly repeat it; check status with a read tool or send the case to review.
What to double-check
- Prompt boundaries: State that tool arguments must come from the user’s authorized request, not from instructions found in retrieved documents, web pages, emails, or tool results. This helps reduce prompt-injection risk, but it does not replace server-side controls.
- Least privilege: Give the tool service only the permissions it needs. A read-only search tool should not share credentials with a deletion tool.
- Data exposure: Return the minimum result needed for the next step. Redact tokens, passwords, private keys, and unnecessary personal data before the model sees the response.
- Concurrency: Decide what happens if two calls update the same resource. Use version checks, locks, or conflict responses where appropriate.
- Observability: Log request ID, user or service identity, tool version, validated arguments with sensitive fields redacted, approval state, outcome, latency, and error category.
- Evaluation: Test correct tool selection, refusal of out-of-scope requests, argument accuracy, authorization boundaries, duplicate-call behavior, and recovery from failures. The LLM evaluation guide can help organize these cases.
- Cost and routing: Limit unnecessary tool loops and large result payloads. Caching, bounded turns, and model routing should be considered alongside the tool contract; see the LLM cost optimization guide.
Common mistakes
Giving the model a generic API wrapper
A tool such as call_api with a URL, method, headers, and arbitrary body transfers too much authority to the model. Expose named business operations instead, with server-controlled destinations and credentials.
Trusting the schema as authorization
A schema can confirm that an ID is a string; it cannot confirm that the current user may access the record behind that ID. Always authorize after resolving the resource on the server.
Allowing hidden defaults
Defaults can create surprising actions. Make consequential fields explicit, or display the resolved default during approval. Keep defaults in version-controlled application code rather than relying only on prompt wording.
Retrying every error
Retries are useful for selected transient failures, but dangerous for payments, messages, updates, and other side effects. Use idempotency and status checks before repeating an uncertain operation.
Changing contracts without versioning
Renaming a field or changing an enum can break prompts, evaluations, approval screens, and downstream consumers. Version the tool contract, retain compatibility where practical, and test old conversations or queued jobs before rollout.
When to revisit
Review each tool before adding a new permission, endpoint, parameter, model, provider, or workflow step. Revisit it after an incident, repeated validation failure, unexplained duplicate action, authorization change, or material change to the underlying API. A seasonal planning cycle is also a useful checkpoint for reviewing dormant tools, approval rules, access scopes, and monitoring coverage.
Provider tool-calling syntax, supported structured-output features, SDK behavior, and argument limits can change. Recheck the relevant provider documentation and run your contract tests at least every six months, and again after a major API or SDK release. Do not update production schemas solely because a provider changed its examples; first confirm compatibility with your application and stored workflows.
Use this short release checklist:
- Can the tool name and description lead the model to the correct action without ambiguity?
- Are arguments strict, bounded, versioned, and validated independently of the model?
- Are identity, authorization, resource scope, and business limits checked server-side?
- Are high-impact actions paused for approval with an exact, reviewable proposal?
- Are retries, timeouts, duplicate calls, and uncertain outcomes defined?
- Are logs, redaction, evaluation cases, rollback steps, and owner responsibilities documented?
When these answers remain clear, tool calling becomes a controlled interface in your LLM application rather than an opaque extension of the prompt. Re-run the checklist whenever the workflow or its tools change, then keep the tested contract close to the code that enforces it.