Tool Calling: Bridging AI and Execution
Language models are text prediction engines. They do not have internet access, database connections, or file execution rights. Tool calling is the standard handshake that lets the model ask the client application to run external code, returning the results back to the context.
The execution loop: The model writes a request, the client intercepts and runs it against the target system, and passes the result back. The model never runs the code itself.
The four stages of a secure tool invocation.
Injection
The client app sends the system prompt along with schemas of available tools. Each schema declares parameters, argument types, and a narrative description.
Intent
The model reasons and generates a structured block containing tool name and specific argument parameters. It pauses text generation and enters a wait state.
Run
The client app intercepts the structured block, executes the function locally or remotely, and captures the string response or database table payload.
Feedback
The client app appends the captured tool response to the prompt history as a tool message. The model resumes execution with the new reference context.
Schema declaration vs. the matching model intent request.
{
"name": "get_customer_balance",
"description": "Fetch customer outstanding balance by ID",
"parameters": {
"type": "object",
"properties": {
"customer_id": {
"type": "string",
"description": "Unique CRM account identifier"
}
},
"required": ["customer_id"]
}
}
{
"tool_calls": [
{
"id": "call_t98765",
"type": "function",
"function": {
"name": "get_customer_balance",
"arguments": "{\"customer_id\": \"crm_9831\"}"
}
}
]
}
Four architectural bottlenecks when models invoke tools.
Parameter Hallucination
The model invents arguments not present in the tool's JSON schema (e.g. sending a email address field when the function only supports user IDs).
JSON Malformation
The model breaks brace formatting, forgets to escape quotes, or truncates the argument string before completion, throwing syntax parsing errors.
Type Mismatches
The model sends integers as strings or booleans as integers, breaking runtime validators and typed target handlers (like TypeScript or Go APIs).
Stagnation loops
The tool throws an error message, and the model attempts to invoke the same tool with identical arguments repeatedly, burning API tokens.
"Text generation describes the world. Tool calling changes it."
The client is the compiler and the compiler rules. The model never runs the code directly; the orchestrator intercepts, validates, and executes.
Clear schema descriptions are code dependencies. A poorly described parameter guarantees that the model will guess its usage incorrectly.