From prompts to applications
Tool use connects Claude to your systems, caching makes long contexts affordable, batches handle scale and MCP standardises integrations. Interviewers want the mechanics and the cost reasoning together.
- Tool usetool_use → tool_result, parallel calls and errors.
- EfficiencyPrompt caching and Message Batches.
- IntegrationServer tools and MCP connectors.
Beyond single prompts, real Claude applications call tools, reuse long contexts cheaply and process large jobs offline. These are exactly the topics interviewers use to tell a tutorial-level user from someone who has shipped a product.
1. How does tool use work with Claude?
Pass a tools list, each with a name, a clear description and an input_schema (JSON Schema). When Claude decides to use one, the response has stop_reason: "tool_use" and a tool_use block with an id, the tool name and its input. Your code runs the tool and sends back a user message containing a tool_result block with the matching tool_use_id. Claude then continues.
tools = [{
"name": "get_weather",
"description": "Get the current weather for a city. Use for any question about today's weather.",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string", "description": "City name, e.g. Pune"}},
"required": ["city"],
},
}]
messages = [{"role": "user", "content": "Should I carry an umbrella in Pune today?"}]
response = client.messages.create(model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=messages)
while response.stop_reason == "tool_use":
messages.append({"role": "assistant", "content": response.content})
results = []
for block in response.content:
if block.type == "tool_use":
output = run_tool(block.name, block.input) # your code
results.append({"type": "tool_result", "tool_use_id": block.id, "content": output})
messages.append({"role": "user", "content": results}) # all results in ONE message
response = client.messages.create(model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=messages)2. How do you handle parallel tool calls and tool errors?
Claude may request several tools in one response. Run independent ones concurrently and return all tool_result blocks together in a single user message. If a tool fails, still return a tool_result with is_error: true and a helpful message, so Claude can retry or explain — never silently drop it.
{"type": "tool_result", "tool_use_id": block.id, "is_error": True,
"content": "Order LF-10293 not found. Ask the customer to check the order number."}3. What makes a good tool definition?
A detailed description of what the tool does, when to use it and when not to; precise parameter descriptions with examples; and few, non-overlapping tools. Set strict: true to guarantee the inputs match your schema exactly. Return compact, clearly labelled results.
4. What are server tools?
Tools that Anthropic runs for you on its infrastructure — for example web search, web fetch and code execution. You declare them in tools and their results come back in the same response, with no tool loop in your code. The SDKs also include a tool-runner helper that runs the loop for your own tools automatically.
5. What is prompt caching and how do you use it?
Prompt caching stores a long, unchanging prefix — tools, system prompt, reference documents — so later requests that start with the same bytes read it from cache at a fraction of the normal input price (around a tenth) and with lower latency. Mark the end of the stable part with cache_control, or enable automatic caching. The cache is a prefix match: any change before the breakpoint invalidates it, so keep timestamps and per-request data after it. Confirm hits with usage.cache_read_input_tokens.
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
system=[
{"type": "text", "text": "You answer HR policy questions for employees."},
{"type": "text", "text": hr_policy_text, # long and unchanged
"cache_control": {"type": "ephemeral"}},
],
messages=[{"role": "user", "content": question}], # changes every time
)
print(response.usage.cache_read_input_tokens)6. When would you use the Message Batches API?
For large jobs that do not need an immediate answer — classifying 50,000 tickets, generating product descriptions overnight, running evaluations. You submit many requests at once, each with a custom_id; they are processed asynchronously at about half the normal price. Results can come back in any order, so match them by custom_id.
batch = client.messages.batches.create(requests=[
{"custom_id": f"ticket-{t.id}",
"params": {"model": "claude-haiku-5-5", "max_tokens": 50,
"messages": [{"role": "user", "content": f"Classify: {t.text}"}]}}
for t in tickets
])
# later: poll client.messages.batches.retrieve(batch.id) until processing_status == "ended",
# then iterate client.messages.batches.results(batch.id) and key results by custom_id7. How does MCP fit with Claude?
The Model Context Protocol, created by Anthropic and now an open standard, lets Claude connect to external systems through MCP servers that expose tools, resources and prompts. Claude apps and Claude Code can use MCP servers directly, and the API offers an MCP connector so a request can use tools from a remote MCP server without you writing the integration code.
8. How do you control cost in a Claude-powered product?
Pick the smallest model that meets your quality bar on an evaluation set; tune the effort setting; cache stable prompts; use batches for offline work; keep context lean (trim history, retrieve only relevant documents); cap max_tokens sensibly; and measure cost per completed task, not per request.
Remember
Key points
- Match tool_use_id
Every tool_result must reference its call.
- One message for all results
Return parallel results together.
- Cache the stable prefix
Tools and system first, changing data last.
- Batches ≈ half price
For anything that can wait.
Interview drill
Follow-up questions
What the interviewer asks after your first answer. Turn on practice mode, answer each one aloud, then reveal.
-
1 What does tool_choice do? Intermediate
It controls whether Claude may use tools:
auto(Claude decides) ornone. Older models also allowed forcing a specific tool; on the newest models useautowith a clear instruction, a strict tool schema, or structured outputs instead. -
2 Why might prompt caching show zero cache reads? Intermediate
Something in the prefix changes between requests (a timestamp, an unsorted JSON object, a different tool list), the prefix is shorter than the minimum cacheable size, or the cache expired (about 5 minutes by default, with a 1-hour option).
-
3 How would you build an agent with Claude without writing the loop yourself? Intermediate
Use the SDK's tool runner for your own tools, the Claude Agent SDK for a ready coding/file agent you host, or Claude Managed Agents, where Anthropic runs the loop and a sandbox for you.
-
4 How do you keep a very long agent conversation within the context window? Advanced
Clear old tool results, summarise or compact earlier turns (the API offers server-side compaction), and store long-term notes outside the conversation.
-
5 How do you protect a tool-using Claude app from prompt injection? Advanced
Limit tools and permissions, confirm side-effecting actions with the user, validate tool inputs in code, and treat fetched web pages, emails and files as untrusted data.