How Function Calling (Tool Use) works in practice
Despite the name, a language model never executes code or calls a network endpoint directly during inference. Instead, the developer passes an array of tool declarations alongside the prompt, each defined with a clear name, description, and a strict JSON Schema describing required and optional parameters. Models post-trained for tool use evaluate the conversation and decide whether they can answer directly or need external data/actions first.
When a tool is needed, constrained decoding guarantees the model outputs a valid JSON payload matching the declared schema (for example, `get_order_status({"order_id": "ORD-84920", "postcode": "SW1A 1AA"})`). The host application intercepts this stop reason, validates the arguments against application permissions, executes the real TypeScript or Python function against the database or REST API, and appends the returned result as a `tool` message in the conversation history. The model then reads that result and generates its next tool call or final natural-language answer.
For instance, a UK telecoms provider's broadband diagnostic assistant uses function calling to run live line-sync tests, check local exchange outages, and book Openreach engineer slots directly from a customer chat session.
Why it matters and trade-offs
Function calling turns a conversational text generator into a deterministic integration layer between human intent and enterprise software. Combined with structured outputs and protocols like MCP, it allows models to fetch real-time pricing, run exact arithmetic in Python rather than guessing mentally, and update CRM records reliably.
Tool performance degrades rapidly when developers dump dozens of overlapping functions with vague parameter descriptions into a single prompt. Good tool engineering follows API design discipline: keep tool counts per step small (ideally under 15), use strict enums and regex patterns in JSON Schemas, return concise actionable error messages when a call fails so the model can self-correct, and never bind destructive tools without a permission check.
