Connecting an LLM to functions, APIs, databases, or other tools can turn a conversational prototype into a useful application—but it also introduces permission, validation, reliability, and security concerns. This guide provides a reusable function-calling and tool-use checklist for selecting tools, defining schemas, approving actions, handling failures, testing behavior, and deciding when a workflow is ready for production.
Overview
Function calling, also called tool calling, lets a language model propose a structured call to an application-owned function. The application—not the model—should execute the function, validate its arguments, enforce permissions, and return a controlled result. The model can then use that result to produce a final response or decide whether another permitted tool is needed.
A safe design separates four responsibilities:
- Model reasoning: interpret the user’s request and select an appropriate tool.
- Application control: validate the proposed name and arguments before execution.
- Tool execution: call an API, database, service, or internal function with restricted credentials.
- Response generation: give the model a carefully shaped result, then present a clear answer to the user.
This boundary matters because an LLM output is not inherently trustworthy code. A tool definition is an interface contract, not a permission grant. The application must still check types, ranges, ownership, authentication, authorization, rate limits, and the consequences of each action.
Start with the smallest useful tool surface. A read-only get_order_status function is easier to test and govern than a general-purpose tool that accepts arbitrary URLs, SQL, shell commands, or administrative instructions. If the task can be completed with deterministic application logic, use that logic instead of asking the model to control it.
Checklist by scenario
Scenario 1: Read-only information tools
Read-only tools retrieve information without changing external state. Examples include searching an approved knowledge base, checking inventory, retrieving a calendar entry, or looking up an account record.
- Define exactly what information the tool can retrieve.
- Use a narrow query schema with explicit filters, limits, and pagination rules.
- Apply the user’s identity and access scope in application code, not in the prompt alone.
- Return only fields needed for the next step; avoid exposing unnecessary personal or internal data.
- Set timeouts and result-size limits so a large response does not overwhelm the model.
- Represent “no result,” “partial result,” and “service unavailable” as distinct outcomes.
Scenario 2: Tools that write or trigger actions
Writing data, sending a message, creating a ticket, placing an order, or changing a setting requires a higher level of control.
- Describe the action and its side effects in the tool documentation.
- Require explicit, typed arguments rather than accepting a free-form instruction.
- Validate resource ownership, allowed values, quantity limits, and duplicate requests.
- Use an idempotency key where repeating the same request could create a second action.
- Show a confirmation step for consequential, irreversible, costly, or externally visible actions.
- Log who initiated the request, what arguments were approved, and what result was returned.
A useful confirmation message states the action in plain language: “Create a support ticket for account X with priority high and the following description?” Avoid asking users to approve an opaque JSON object without context.
Scenario 3: Multi-step workflows and agents
When an LLM can call several tools in sequence, define a clear stopping condition. The workflow should know whether it is gathering information, planning an action, executing an approved action, or composing a final answer.
- Set a maximum number of model-tool turns.
- Keep a structured state record for completed steps, pending approvals, and failed calls.
- Prevent the model from treating tool output as new system instructions.
- Require each step to receive only the data it needs.
- Stop and escalate when the model repeats a call, contradicts a previous result, or requests an unavailable tool.
- Design recovery behavior for timeouts, expired sessions, and partial completion.
For longer workflows, persist checkpoints outside the conversation. A separate state design makes retries and human handoffs more predictable. See AI Agent State Management for related patterns.
Scenario 4: Human approval flows
Human approval is most useful when the model can prepare an action but should not finalize it independently. The approval record should include the proposed tool, normalized arguments, affected resource, expected side effect, and expiration time.
- Freeze or revalidate arguments between approval and execution.
- Make approval specific to one action rather than a broad permission to continue.
- Allow rejection, editing, and cancellation.
- Show execution status and provide a recovery path if the action partially succeeds.
Reusable tool-definition template
Use a schema that is narrow, explicit, and easy to validate. The exact syntax varies by model API, but the design principles are portable:
{
"name": "create_support_ticket",
"description": "Create one support ticket after the user has confirmed the details.",
"parameters": {
"type": "object",
"properties": {
"subject": { "type": "string", "minLength": 1, "maxLength": 120 },
"description": { "type": "string", "minLength": 1, "maxLength": 5000 },
"priority": { "type": "string", "enum": ["low", "normal", "high"] }
},
"required": ["subject", "description", "priority"],
"additionalProperties": false
}
}
Keep descriptions operational. Explain what the function does, when it should be used, what it must not do, and whether confirmation is required. Do not rely on descriptions as the only security control.
What to double-check
Before enabling a tool, review the complete path from prompt to external effect.
| Area | Questions to ask |
|---|---|
| Tool selection | Could the model confuse this tool with another? Is the tool necessary, narrow, and clearly named? |
| Schema | Are required fields, enums, lengths, formats, defaults, and unknown fields handled explicitly? |
| Validation | Does application code validate every argument independently of the model output? |
| Permissions | Are credentials scoped to the user, tenant, resource, and operation? |
| Prompt injection | Could retrieved content or user-provided text influence tool selection or override application rules? |
| Failure handling | Can the system distinguish invalid input, denied access, timeout, rate limit, and provider failure? |
| Observability | Can you trace the request, tool call, validation decision, result, latency, and final response without logging secrets? |
| Concurrency | If multiple calls are allowed, can they safely run in parallel, or must they be ordered? |
Test both successful and adversarial inputs. Include missing fields, wrong types, very long strings, unexpected properties, ambiguous resource names, duplicate submissions, expired authorization, and tool responses containing instructions. Tool results should be treated as data. They should not be allowed to rewrite system-level rules or bypass a confirmation requirement.
Use an evaluation set that reflects real application behavior rather than testing only ideal prompts. Record whether the model selected the right tool, supplied valid arguments, asked for missing information, respected approval requirements, and produced an accurate final response. The LLM Evaluation Guide can help structure these comparisons, while Prompt Injection Defense for LLM Apps covers related threat testing.
Common mistakes
- Giving the model broad capabilities: A generic HTTP, database, filesystem, or code-execution tool makes authorization and auditing difficult. Wrap approved operations in narrow functions.
- Trusting schema validation alone: A correctly typed account ID can still belong to the wrong user. Validate business rules and permissions after parsing.
- Using ambiguous tool names: Names such as
process_requesthide important differences. Prefer action and object names such aslookup_invoiceorcancel_subscription. - Retrying every failure: Automatic retries can duplicate writes or worsen rate limits. Retry only classified transient failures, and use idempotency for eligible actions.
- Returning raw errors to the model: Internal stack traces, credentials, and implementation details can leak into the conversation. Map failures to safe, structured categories.
- Skipping the final-response check: The tool may succeed while the model describes the wrong result. Ground the final response in the actual tool output and expose uncertainty when information is incomplete.
- Changing tools without regression tests: A renamed field, altered default, or new parallel-call behavior can affect prompts and orchestration. Track tool definitions like code.
Keep prompt and tool changes reviewable. Version definitions, test representative scenarios, and compare results before release. The workflow described in AI Prompt Versioning is also applicable to tool descriptions and orchestration prompts.
When to revisit
Revisit this checklist whenever you add, remove, or modify a tool; change a schema; alter permissions; switch models or providers; enable parallel calls; introduce streaming; change retrieval sources; or move from an internal prototype to a user-facing workflow. Provider APIs and orchestration libraries can also change how tool definitions, structured outputs, retries, and call sequencing behave, so verify current documentation during an implementation update rather than assuming examples remain identical.
Before each release, run a focused review:
- List every available tool and its permitted side effects.
- Recheck schemas against the application validators.
- Run happy-path, malformed-input, permission, injection, timeout, duplicate, and partial-failure tests.
- Confirm that write actions still require the intended approval or authorization.
- Inspect logs for useful traces without retaining unnecessary sensitive data.
- Review latency, retry limits, token usage, and maximum tool-call depth.
- Update prompt, tool, and evaluation versions together so a regression can be traced.
Finally, test the workflow with the actual tools and representative data before expanding access. A reliable LLM application is not defined by how confidently the model proposes a function call; it is defined by whether the surrounding system makes valid actions possible, invalid actions difficult, and failures understandable.