1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
51 small wins to finish your pathNext question →
How does tool calling (function calling) actually work under the hood?
30-second answerSay your answer out loud first, then reveal.
Step by step

- Definition. You describe each tool with a name, a natural-language description, and a JSON Schema for its parameters. These are injected into the model's context, often in a special format the model was trained on.
- Decision. The model was fine-tuned to emit a special structured block when it decides a tool is useful. Many APIs return this as a separate
tool_callsfield with astop_reasonsuch as "tool_use". - Execution. Your application validates the arguments, runs the real function, and handles errors.
- Result. You append the tool result to the conversation, linked to the call by an ID, and call the model again.
- Loop. The model either calls more tools or produces a final answer.
Key points interviewers look for
- Security boundary. Since your code executes the tool, you enforce permissions, validation and rate limits. Never trust model-generated arguments blindly.
- The description is a prompt. Tool descriptions strongly affect which tool gets chosen and when.
- Parallel calls. Most APIs let the model request several tools in one turn (see Q30).
- Forcing.
tool_choicecan force a specific tool, require any tool, or disable tools.
Common mistakes
- Saying "the LLM calls the API." It only requests the call.
- Forgetting to validate arguments against the schema before execution.
Follow-ups to expect
- What happens if the model returns invalid JSON arguments?
- How do you handle a tool that takes 2 minutes to run?
Related
Slow is fine. Stopping is the only problem.