Tool calling
Tool calling lets a model propose a named operation with arguments. Application code validates and executes permitted operations, then returns the result.
Before you start: Review Structured output first. Python-like examples use variables, lists and functions.
Follow the mechanism
Proposal
The model requests a named operation.
Start with an everyday explanation
An assistant can fill in a request slip. The service desk checks the slip and the requester before doing the work. A proposed operation is not an executed operation.
See a concrete example
lookup_policy({id:POL-42}) is checked against the signed-in user. A payment tool additionally requires explicit approval and a deduplication key.
A claim to question
The model does not safely execute arbitrary code just because it returned a tool name.
Try before revealing the answer
Sketch a dispatcher that rejects an unknown tool and a policy ID belonging to another user.
Show the worked answer
Check the allowlist, validate arguments, authorize the resource, execute with a timeout and return a typed result. Never use eval on model-provided text.
Now explain the idea to someone else using your own example. If you cannot explain a stage, revisit it before moving on.
Engineering details and trade-offs
Use explicit schemas, allowlisted tools, argument validation and user-scoped credentials. Separate read-only lookups from side effects.
Set timeouts and call budgets. Use idempotency keys where retries can duplicate writes, and distinguish rejected, failed and successful results.
Reason through the example
lookup_policy({id:POL-42}) is checked against the signed-in user. A payment tool additionally requires explicit approval and a deduplication key.
Implement and test
Sketch a dispatcher that rejects an unknown tool and a policy ID belonging to another user.
Inspect the reasoning and expected result
Check the allowlist, validate arguments, authorize the resource, execute with a timeout and return a typed result. Never use eval on model-provided text.
What to measure
State the expected result before changing a control. Record your inputs, compare the observed result and explain one limit of this model. In a real implementation, test the failure case as well as the normal path.
Answer before reading the reference
How do you make tool retries safe?
A defensible answer
Classify operations, use bounded backoff for eligible transient failures and deduplicate side effects with idempotency keys. A timeout may hide a committed write, so reconcile status before retrying.
Prepare the follow-up
How do you prevent a document from choosing an exfiltration destination?
Show follow-up reasoning
Use application-controlled destination allowlists, user-scoped permissions and payload-bound approval for sensitive sends. The model cannot obtain a new destination privilege from retrieved text. Validate URLs and redirects when tools fetch external content, and exclude credentials from untrusted context.
Use the engineering explanation and worked task above to support your response. Identify which assumptions you would need to verify in production.
Choose a practice depth
- New to GenAI
- Define tool calling with the everyday example and name its key limitation.
- Applied experience
- Explain the example, implementation choice and a measured failure case. Use the exercise as a small design review.
- Senior or systems depth
- Answer the follow-up, compare alternatives and justify an evaluation or rollout plan with operational constraints.
Self-review your answer
0/4 checks selected. This is self-assessment, not an interview score.
Your explanation and revision notes
Loading local notes…