Tool Calling
The model asks for an action with a tool name and arguments. The harness checks the request, runs the tool, and gives the result back. For example, an order lookup gives the delivery status for the reply.
4 min read4 মিনিটে পড়া যায় · 5 sections5টি সেকশন · 4 sources4টি সোর্স · updated Nov 2026আপডেট: Nov 2026
One tool call, step by stepএকটা টুল কল, ধাপে ধাপে
Follow a get_order request from the model to the harness and back, with the id intact. Then make the tool fail.একটা get_order অনুরোধ মডেল থেকে harness-এ আর ফেরত যেতে অনুসরণ করুন, id ঠিক রেখে। তারপর টুলটা ব্যর্থ করান।
You’ll learnআপনি শিখবেন
- What a tool definition holdsটুল ডেফিনিশনে কী থাকে✓
- Why the model never runs the toolমডেল কেন নিজে টুল চালায় না
- How tool_use_id matches a result to its requesttool_use_id কীভাবে ফলকে অনুরোধের সাথে মেলায়
- What is_error lets the model dois_error মডেলকে কী করতে দেয়
Define a tool
A tool definition has three main fields Source 2সোর্স 2:
| Field | Content |
|---|---|
name | The name of the tool. It must match ^[a-zA-Z0-9_-]{1,128}$. |
description | A plain text description of what the tool does, when to use it, and how it behaves |
input_schema | A JSON Schema object for the parameters of the tool |
This definition gives the model an order lookup tool:
{
"name": "get_order",
"description": "Get the delivery status of one order. Use it when the customer asks where an order is.",
"input_schema": {
"type": "object",
"properties": {
"order_id": { "type": "string", "description": "The order ID, for example A-1001" }
},
"required": ["order_id"]
}
}The model does not run the tool. It decides when to call it from the request and the description, and your application runs the call Source 1সোর্স 1.
If you add strict: true to a custom tool definition, the tool calls of Claude always match your schema exactly Source 1সোর্স 1.
সহজ English
To give the model a tool, you describe the tool in three parts Source 2সোর্স 2:
- A name, for example
get_order. - A description in plain words: what the tool does and when to use it.
- An input schema: the inputs that the tool needs, for example an order ID.
The model never runs the tool itself. It reads the request of the user and this description, and decides when to ask for the tool Source 1সোর্স 1.
If you add strict: true to the definition, the requests of the model always match your input schema exactly Source 1সোর্স 1.
বাংলা ব্যাখ্যা
মডেলকে একটা টুল দিতে হলে টুলটাকে তিনটা অংশে বর্ণনা করতে হয় Source 2সোর্স 2:
- একটা name, যেমন
get_order। - সহজ ভাষায় একটা description: টুলটা কী করে আর কখন ব্যবহার করতে হবে।
- একটা input_schema: টুলের কী কী ইনপুট লাগে, যেমন একটা order ID। এটা একটা JSON Schema।
মডেল নিজে কখনো টুল চালায় না। সে ইউজারের রিকোয়েস্ট আর এই বর্ণনাটা পড়ে ঠিক করে কখন টুলটা চাইবে Source 1সোর্স 1।
ডেফিনিশনে strict: true দিলে মডেলের রিকোয়েস্ট সবসময় হুবহু আপনার schema মেনে চলে Source 1সোর্স 1।
The request and the result
When Claude wants a tool, the response has stop_reason: "tool_use" and one or more tool_use blocks. Your code runs the operation and sends back a tool_result Source 1সোর্স 1. A tool_use block has an id, the name of the tool, and an input object that Claude builds from the input_schema Source 3সোর্স 3. Without strict: true it can still be invalid, so validate it:
{ "type": "tool_use", "id": "toolu_01A", "name": "get_order", "input": { "order_id": "A-1001" } }Your code runs the tool that has that name, with that input Source 3সোর্স 3. Then it sends a new user message with a tool_result block. Its tool_use_id is the id of the request Source 3সোর্স 3:
{ "type": "tool_result", "tool_use_id": "toolu_01A", "content": "delivered" }The model uses the result in its reply, for example "Your order was delivered."
If the tool fails, set is_error to true and put the error message in content Source 3সোর্স 3. Claude can then call the tool again or tell the user what happened Source 3সোর্স 3. Limit how many retries your loop allows.
সহজ English
The steps of one tool call are Source 1সোর্স 1:
- The model stops and says "I want to use
get_orderwith orderA-1001". The API marks this stop with the reasontool_use. - Your code runs the real order lookup Source 3সোর্স 3.
- Your code sends the result back, with the ID of the request, so the model knows which request it answers Source 3সোর্স 3.
- The model writes the reply: "Your order was delivered."
If the lookup fails, your code says so with is_error: true and an error message Source 3সোর্স 3. Then the model can try the tool again or tell the user about the error Source 3সোর্স 3.
বাংলা ব্যাখ্যা
একটা টুল কলের ধাপগুলো হলো Source 1সোর্স 1:
- মডেল থামে আর বলে "আমি
A-1001অর্ডারের জন্যget_orderব্যবহার করতে চাই"। API এই থামাকেstop_reason: "tool_use"দিয়ে চিহ্নিত করে। - আপনার কোড আসল order lookup-টা চালায় Source 3সোর্স 3।
- আপনার কোড একটা
tool_resultফেরত পাঠায়, সাথে রিকোয়েস্টের ID (tool_use_id), যাতে মডেল বোঝে কোন রিকোয়েস্টের উত্তর এটা Source 3সোর্স 3। - মডেল উত্তর লেখে: "আপনার অর্ডার ডেলিভারি হয়ে গেছে।"
lookup ফেল করলে আপনার কোড is_error: true আর একটা এরর মেসেজ দিয়ে সেটা জানায় Source 3সোর্স 3। তখন মডেল আবার টুলটা চাইতে পারে, অথবা ইউজারকে এররটা জানাতে পারে Source 3সোর্স 3।
Where the tool runs
Tools differ mainly by where the code runs Source 1সোর্স 1:
| Kind | Where it runs | Example |
|---|---|---|
| Client tools | In your application Source 1সোর্স 1 | The user-defined get_order tool |
| Server tools | On Anthropic's infrastructure Source 1সোর্স 1 | web_search, web_fetch, code_execution |
For a client tool, your application runs each call Source 1সোর্স 1, so the check before the run is your job. For server tools, you do not need to handle is_error results Source 3সোর্স 3.
The model can also ask for several tools in one turn. The response then has several tool_use blocks Source 4সোর্স 4. Return one tool_result for each tool_use block, all together in the next user message Source 4সোর্স 4. If you do not run one of the calls, still return a tool_result for it, with is_error: true and a short explanation Source 4সোর্স 4.
সহজ English
A tool runs in one of two places Source 1সোর্স 1:
- A client tool runs in your own application, for example your order lookup Source 1সোর্স 1. Your code must check each request before it runs it.
- A server tool runs on Anthropic's servers, for example web search Source 1সোর্স 1.
The model can ask for several tools at the same time Source 4সোর্স 4. Your code then sends all the results back together in one message Source 4সোর্স 4. If your code skips one request, it still answers that request with an error and a short reason Source 4সোর্স 4.
বাংলা ব্যাখ্যা
একটা টুল দুই জায়গার একটায় চলে Source 1সোর্স 1:
- client tool আপনার নিজের অ্যাপ্লিকেশনে চলে, যেমন আপনার order lookup Source 1সোর্স 1। প্রতিটা রিকোয়েস্ট চালানোর আগে আপনার কোডকেই সেটা চেক করতে হবে।
- server tool Anthropic-এর সার্ভারে চলে, যেমন
web_searchSource 1সোর্স 1।
মডেল একসাথে কয়েকটা টুল চাইতে পারে Source 4সোর্স 4। তখন আপনার কোড সব tool_result একসাথে একটা মেসেজে ফেরত পাঠায় Source 4সোর্স 4। কোনো একটা রিকোয়েস্ট না চালালেও তার জন্য is_error: true আর ছোট একটা কারণ দিয়ে উত্তর দিতে হয় Source 4সোর্স 4।
What a tester can check
Tutorial advice
A tool call is an input from the model to your code. Test it like any other input:
- Bad arguments: a missing
order_id, a wrong type, or an ID of an order of another customer. - Tool failure: a timeout or a 500 from the order service. The reply must not say "delivered".
- Unknown tool: a request for a tool name that does not exist.
- Parallel calls: two lookups in one turn. Each result must go back with the correct
tool_use_id. - Description quality: a vague description makes the model pick the wrong tool. Test the prompts that sit between two tools.
সহজ English
Tutorial advice
Treat each tool request as input that can be wrong:
- A missing or wrong order ID, or the order of another customer.
- The order service is down. The reply must not say "delivered".
- A request for a tool that does not exist.
- Two lookups at the same time. Each result must match its request.
- A vague tool description that makes the model pick the wrong tool.
বাংলা ব্যাখ্যা
Tutorial advice
প্রতিটা টুল রিকোয়েস্টকে এমন ইনপুট ভাবুন, যেটা ভুল হতে পারে:
- order ID নেই, ভুল, বা অন্য কাস্টমারের অর্ডার।
- order সার্ভিস বন্ধ। তখন উত্তরে "ডেলিভারি হয়ে গেছে" বলা যাবে না।
- এমন টুলের রিকোয়েস্ট, যেটার অস্তিত্ব নেই।
- একসাথে দুটো lookup। প্রতিটা ফলাফল তার নিজের রিকোয়েস্টের সাথে মিলতে হবে।
- অস্পষ্ট description, যার কারণে মডেল ভুল টুল বেছে নেয়।
Key words
| Term | Meaning |
|---|---|
| Tool definition | The name, description, and input_schema of a tool |
tool_use | The block in which the model asks for a tool, with an id and an input |
tool_result | The block in which your code returns the result, with the tool_use_id |
stop_reason: "tool_use" | The model stopped because it wants a tool |
is_error | Set to true in a tool_result when the tool failed |
| Client tool | A tool that runs in your application |
| Server tool | A tool that runs on Anthropic's infrastructure |
strict: true | Makes the tool calls match the schema exactly |