Varun Vemulapalli

Day 68 of 100 · Phase 9: Claude for builders

Tool use with the Claude API

2 min readBy Varun Vemulapalli

Ask a model "Is my flight on time?" and it can only guess. It has no live airline data.

Give it a tool, and it asks your code to check, then answers from the real result.

Here's the exchange, step by step.

Video explainer · 1:43
Key takeaway

With tool use, Claude asks for a function call in JSON, your code runs it and returns a matching tool_result, and the answer is grounded in real data.

Day 68 visual: Tool use with the Claude API
The visual from the original post.

The concept

Tool use: you describe functions your app can run; Claude decides when one is needed and replies with a structured request. Your code runs it and sends back the result. Claude never runs your code itself (the idea is from Day 37; today is the Claude API version).

A tool definition has three fields:

  • name: get_flight_status
  • description: what it does and when to use it. Anthropic's docs call it the biggest factor in tool performance; aim for 3–4 sentences.
  • input_schema: a JSON Schema of the inputs, here flight_number (string) and date (string, YYYY-MM-DD).

Walkthrough: a travel assistant, four messages

1. You send the user's question plus the tools list:
"Is flight XY123 on 12 December on time?"

2. Claude replies with stop_reason "tool_use" and a block like:
{"type":"tool_use","id":"toolu_01...","name":"get_flight_status","input":{"flight_number":"XY123","date":"2026-12-12"}}

3. Your code queries your flight data and sends a user message with:
{"type":"tool_result","tool_use_id":"toolu_01...","content":"Delayed 40 min, new departure 18:10, gate B7"}
(illustrative data; tool_use_id must match the id from step 2)

4. Claude answers: "XY123 is delayed about 40 minutes, now leaving 18:10 from gate B7."

If the lookup fails, return the error with "is_error": true so Claude says so instead of inventing a time.

Your code stays in control: it decides which tools exist, checks inputs, and keeps actions like rebooking behind human approval.

Where you see it at work

  • Customer experience: order, delivery and appointment lookups.
  • Banking: balance or card-status checks through narrow, read-only tools.
  • Insurance: claim-status lookups by claim number.
  • Healthcare: clinic slot availability checks.
  • Product management: each tool is a feature with its own rules.

Try it today (10–15 min)

1. Read how the loop works: https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works
2. Write the get_flight_status definition on paper: name, 3–4 sentence description, input_schema.
3. Extend yesterday's script: pass tools=[your definition], print response.stop_reason and the tool_use block. Return a fake status as a tool_result and see the final answer.
4. Field reference: https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls

In one sentence

With tool use, Claude asks for a function call in JSON, your code runs it and returns a matching tool_result, and the answer is grounded in real data.

Which lookup would you give an assistant first? 👇