🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

Tool-Calling: Giving a Model Real Options

Send your real tool schemas to a live model and watch it choose one based purely on names, descriptions, and the question asked.

Total XP: 0|💻 mcpmasterclass XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Tool-Calling

The model chooses; you execute.

Quick Quiz //

What information does a model use to decide which tool to call?


🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.

The moment a schema stops being documentation and starts actually shaping what a model decides to do.

1The tools Field Changes What a Model Can Return

Passing a tools array in a chat completion request tells the model it's allowed to respond with a structured tool_calls entry instead of plain text, whenever it judges a tool would answer the question better than generating text alone. The model itself decides — you're offering options, not issuing a command.

2Tool Selection Is Entirely Schema-Driven

The model has no access to your handler code, your registry, or your data — only the name, description, and parameters you send in the tools array. This is exactly why the schema-writing work from Module 1 matters: a vague description leads directly to the model picking the wrong tool, or no tool at all.

3Step-by-Step Breakdown

Handing Your Tools to a Real Model. A model can only decide to call a tool if it's actually told the tool exists. This lesson sends your real read_file and list_files schemas to a live model alongside a real question — watch it decide, on its own, which tool (if any) to call first.

Watch a Real Model Choose a Tool. Ask about the project's files with both real tools available. Look at the response closely: instead of text, a well-behaved model returns a tool_calls entry naming exactly one of your tools with concrete arguments — it decided list_files is the right first step, without being told which tool to use.

The model was never told 'use the list_files tool.' How did it decide to call it instead of just answering in plain text?

  • It reasoned from each tool's name, description, and schema that list_files matched the question better than answering from its own (nonexistent) knowledge of your project's files.
  • The API silently forces every request that mentions a folder to trigger a tool call.

A Decision, Not Yet an Answer. The model decided to call a tool — but nothing actually ran yet. It just produced a tool_calls entry describing what it wants. Your server still has to parse that, run the real handler, and get a real result. Next lesson: doing exactly that.

Level Up 🚀

Advanced cheat sheets, SEO tricks, and interview prep for this topic.

Browser Support

ChromeSupported

Fully supported.

FirefoxSupported

Fully supported.

SafariSupported

Fully supported.

EdgeSupported

Fully supported.

Accessibility (A11y)

1Surface Which Tool Was Called in Any Chat UI

When a model's turn is a tool call rather than a text reply, render that explicitly (e.g. 'Called list_files') rather than showing a blank or loading state with no explanation.

<span>🔧 Called list_files(prefix="src/")</span>

SEO Implications

  • 1

    Target 'OpenAI function calling tutorial' and 'MCP tool selection example' separately

    Developers search for the underlying API mechanic and the MCP-specific schema-to-tool-call flow as distinct concerns.

Best Practices

Offer Only the Tools Relevant to the Current Task

Sending every tool your server has on every request gives the model more chances to pick the wrong one — scope the tools array down when you already know the likely task.

Frequent Bugs

THE BUG

Assuming a tool_calls response means the tool already ran.

THE FIX

A tool call is only the model's request to run something — your code still has to parse it, execute the real handler, and feed the result back before there's a final answer.

Real-World Examples

Multi-Tool Assistants

A coding assistant offered read_file, run_tests, and git_log at once relies entirely on well-written descriptions to pick the right one per question — ambiguous descriptions measurably increase wrong-tool selections.

tools = [read_file, run_tests, git_log]

Interview Prep

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Full-Stack Software and AI Engineer

Full-Stack Software and AI Engineer with 6 years of experience building enterprise-grade web applications across React, Angular, Node.js, and Python. Recently completed a Master's in AI Development specializing in LLMs, RAG, and AI agent architectures, and currently builds enterprise systems that integrate AI and Digital Twins to optimize industrial and logistics processes.

LinkedIn ↗
Common Pitfalls & Errors

The Error //

Hardcoding sensitive credentials

// Wrong const API_KEY = 'sk-123456789'; // Correct const API_KEY = process.env.API_KEY;

The Solution //

Never hardcode API keys, passwords, or secrets in your source code. Use environment variables (.env files) to keep them secure and out of version control.

Lesson Glossary

[01]tool_calls

The part of a model's response naming which tool(s) it wants to call and with what arguments, in place of plain text.

Code Preview
response.tool_calls[0].function.name

[02]Function Calling

The general LLM API feature (also called tool calling) that lets a model select from developer-provided function schemas.

Code Preview
tools: [{ type: "function", ... }]

Continue Learning