What is Function Calling?
Function Calling is a large-language-model capability that produces a structured proposal naming a tool and its arguments; trusted application code must validate, authorize, execute, and return the result.
Quick Facts
| Full Name | LLM Function Calling |
|---|---|
| Created | 2023 by OpenAI |
| Specification | Official Specification |
How It Works
Function Calling connects natural-language requests to bounded software capabilities, but the model does not execute a function on its own. It proposes a tool name and structured arguments; a deterministic executor resolves the tool, derives identity and tenant from trusted context, validates business state, authorizes the exact effect, applies timeouts and idempotency, and returns a normalized result. Schema validation makes arguments easier to parse, not safe or true: it cannot establish ownership, current prices, consent, or whether a write should occur. MCP can standardize discovery and transport for external tools, while function calling is a model-facing interface; both still require host-side policy, approval, output handling, and audit.
Key Characteristics
- A model proposal separated from deterministic execution
- Schemas that constrain shape but do not grant authority
- Trusted runtime context for identity, tenant, and permissions
- Bounded multi-call loops with time, cost, and repetition limits
- Idempotent write semantics, previews, and approval for consequential effects
- Untrusted tool-result handling, tracing, and trajectory evaluation
Common Use Cases
- AI agents that use narrowly scoped external services
- Customer-support systems that preview actions before submitting them
- Natural-language workflows with audited tool boundaries
- MCP hosts that translate discovered tools into an approved runtime registry
- Voice or chat assistants that require explicit confirmation for writes
Example
Loading code...Frequently Asked Questions
How does function calling differ from regular text generation?
Regular generation returns free-form content. Function calling returns a structured proposal identifying a tool and arguments so application code can interpret it. The structure improves parsing, but it does not execute an action or prove that the action is correct, authorized, or safe; the executor must enforce those properties.
Can the model call multiple functions in a single response?
Many providers can return several proposed calls. Run them concurrently only when they are truly independent, read-only, or safely idempotent. Calls that share state, consume a quota, depend on an earlier result, or cause a side effect need deterministic ordering and a failure policy; the model's grouping is not proof that parallel execution is safe.
How do I handle errors when the model calls functions incorrectly?
Validate argument shape, resolve the target resource, authenticate and authorize the caller, validate current business state, then normalize a bounded error result. Retry only failures that are safe to retry: never blindly repeat an ambiguous write. Do not expose stack traces, secrets, or internal topology to the model, and treat every tool result as untrusted input.
What is the relationship between function calling and AI agents?
Function calling is a fundamental building block for AI agents. Agents use function calling to interact with their environment—reading data, taking actions, and responding to results. The agent loop typically involves: receive user input, decide which function(s) to call, execute them, observe results, and repeat until the task is complete. Function calling enables this tool-use capability.
How should I design function schemas for optimal model performance?
Expose narrow business-intent operations, with clear names, descriptions, required fields, bounded values, and no ambiguous overlap. Do not ask the model to provide trusted fields such as user ID, tenant, role, price, or approval state; derive them in the executor. There is no universal safe tool-count threshold, so evaluate selection accuracy and latency using representative tasks for your system.