Use Tool Search

Su Suriya Ravichandran Updated 10 Nov 2026
6 min read ·Lesson 154 of 200

When the Tool Catalog Is Larger Than the Conversation

Every tool in a request is described to Claude, with its name, its description, and its input schema. Those definitions are input tokens, and they are sent with every request in the conversation. For an application with a handful of tools, the cost is small. For a platform with hundreds of integrations, each with several operations, the definitions alone can outweigh the conversation they serve. They also crowd the context, so the model has more to consider on every turn than the task requires.

Tool search addresses that problem. Instead of loading every definition up front, the application marks most tools as deferred, and gives Claude a search capability. When a request needs a tool, Claude searches the catalog, and only the matching definitions are loaded for that step. The rest of the catalog stays out of the request until it is needed.

This lesson explains the pattern, its effect on cost and on the cache, and how to design a catalog so search finds the right tool. A simulation at the end shows the selection step on a catalog of three hundred tools.


Deferred and Loaded Tools

Tools fall into two states in this pattern:

StateWhat is sentWhen it applies
LoadedThe full definition: name, description, and schemaTools the application always needs, and tools the search has selected
DeferredOnly enough to be found by searchThe rest of the catalog

The documentation describes marking tools for deferred loading with a defer_loading setting on each tool definition. A deferred tool is not usable until it is loaded, and loading happens through the search mechanism. The distinction is important for cost, and for the cache: a catalog that changes on every request invalidates the cached tool prefix, while a stable catalog with deferred loading keeps the prefix steady, as Lesson 128 showed for tool definitions.

The exact field names and the search tool's type identifier are defined in the tool search documentation, and they should be copied from there rather than from memory. The pattern itself is the important part, and it is the same regardless of the exact spelling.


What Search Needs

Search can only find a tool whose description tells it what the tool is for. A tool named op_4417 with no description will never be selected, however useful it is. Good catalog design for search therefore follows rules that also help the model choose tools directly:

ElementGuidance
NameDescriptive and consistent, such as billing_refund_order
DescriptionSays what the tool does, the domain it belongs to, and when to use it
VocabularyUses the words users actually say: refund, cancel, track, not only internal codes
GroupingRelated tools share a domain word, so search can find the family

Lesson 93 described tool docstrings in depth. The same content serves search, because the search matches against the same text Claude reads.


When Tool Search Pays Off

Tool search adds a step, and that step has a cost of its own. It is worth using when the definitions of the tools that are not needed would be a large share of the request. A rough test is to estimate the tokens of the full catalog, and compare them with the tokens a typical request actually needs. When the full catalog dominates, deferral pays. When the catalog is small, the overhead of searching can exceed the saving, and loading everything is simpler.

The estimate can be rough. Tokens are usually a fixed multiple of characters, so the length of the serialized definitions gives an order of magnitude, and count_tokens() (Lesson 158) gives the exact figure for a specific request.


Simulating Selection

The simulation below builds a catalog of three hundred tools in five domains. It selects the tools whose description or name matches the words in a request, the way a search would, and it reports how little of the catalog was needed. The matching is deliberately simple, so the behavior is easy to follow:

"""tool_search_sim.py: select a few relevant tools from a large catalog, by word matching."""

import re

DOMAINS = ["billing", "shipping", "inventory", "support", "analytics"]
CATALOG = [
    {
        "name": f"{domain}_action_{number}",
        "description": f"Performs {domain} action {number} for the store team. "
                       "Accepts record identifiers and returns status details.",
    }
    for domain in DOMAINS
    for number in range(60)
]


def words(text: str) -> set[str]:
    return set(re.findall(r"[a-z]+", text.lower()))


def search(query: str, catalog: list[dict], limit: int = 5) -> list[dict]:
    query_words = words(query)
    scored = []
    for tool in catalog:
        score = len(query_words & words(tool["name"] + " " + tool["description"]))
        if score:
            scored.append((score, tool))
    scored.sort(key=lambda pair: (-pair[0], pair[1]["name"]))
    return [tool for _, tool in scored[:limit]]


if __name__ == "__main__":
    chosen = search("Refund the billing charge for this customer", CATALOG)
    print("catalog size:", len(CATALOG))
    print("loaded:", [tool["name"] for tool in chosen])
    print(f"share of catalog loaded: {len(chosen) / len(CATALOG):.1%}")

Output:

catalog size: 300
loaded: ['billing_action_0', 'billing_action_1', 'billing_action_10', 'billing_action_11', 'billing_action_12']
share of catalog loaded: 1.7%

How It Works

  1. The catalog is built from domains. Five domains of sixty tools each give three hundred tools, and every tool carries its domain word in its description, as good catalog design requires.
  2. words() reduces text to lowercase words, so matching ignores case and punctuation. The query "Refund the billing charge for this customer" contributes the word billing, along with other words no tool uses.
  3. search() scores each tool by shared words, and ignores tools with no match. Every billing tool scores the same, so the tie is broken by name, which makes the output reproducible.
  4. Only five tools are loaded, which is 1.7% of the catalog. Sending the other 295 definitions would have cost far more, for tools this request cannot use.
  5. The ordering is alphabetical among ties. A real search ranks by relevance, which is usually better, but the simulation keeps the example exact.

Note: a real tool search is driven by Claude's own query, not by the user's raw wording, and it matches against richer signals than shared words. The simulation shows the principle that a good catalog makes selection possible, not the matching algorithm.


Keeping the Cache Stable

The cache interaction is one of the main reasons to design this carefully. A tool definition change invalidates the tool cache and everything after it (Lesson 127). A catalog that is edited frequently, or that loads a different set of definitions on every request, rewrites the cached prefix each time. Deferred loading keeps the always-loaded definitions stable, and the searched definitions arrive in the conversation as results, after the cached prefix. The design goal is a stable core and a variable periphery.


Validating Search Quality

A search that loads the wrong tool is worse than one that loads too many, because the model then reasons from the wrong definition. Quality should be checked with test queries that have known correct tools, in the same way Lesson 39 checked prompts. A set of fifty requests, each paired with the tool it should load, shows which descriptions are failing. The failures usually point to a description that lacks the words users use, which is an easy fix.


Summary

Tool search keeps a large catalog out of the request until it is needed. Deferred tools are found through search, and only the relevant definitions are loaded for each step. Its value depends on the size of the catalog and on the quality of the descriptions, since search can only find what the text describes. Stable catalogs with deferred loading also protect the cache. The next lesson covers the web search tool, a server-side capability that searches the internet for the model.

0 Comments

Reviewed before they appear

No comments yet.

Anthropic SDK Using Python
Anthropic SDK Intro Claude API Intro SDK Requirements Install Anthropic SDK Upgrade the SDK Create an API Key Set API Keys Use Environment Variables Import Anthropic Create a Client Send Your First Message Choose a Claude Model Set Max Tokens Read a Response Print Response Text Understand Message Blocks Use System Prompts Send User Messages Set Temperature Handle Stop Reasons Messages API Intro Create Messages Use Message Roles Send Conversation History Continue a Conversation Build a Chat Loop Reset Chat History Use Multiple Turns Inspect Message IDs Read Usage Data Write Clear Prompts Set a System Prompt Add Context to Prompts Use Prompt Templates Add Examples to Prompts Request JSON Output Use XML Tags Control Response Length Improve Prompt Quality Avoid Prompt Injection Read Text Blocks Read Content Blocks Check Stop Reasons Count Input Tokens Count Output Tokens Count Tokens Before Sending Limit Output Tokens Use Stop Sequences Read Request IDs Parse API Responses Streaming Intro Stream Text Output Use Stream Events Use Stream Helpers Get Final Messages Stream Async Responses Handle Stream Errors Build a Live Chat Stream Long Responses Close Streams Safely Build a Chatbot Keep Chat History Manage Chat Sessions Add Chat Memory Build a CLI Chatbot Build a Web Chatbot Use Flask with Claude Use FastAPI with Claude Return JSON from an API Add Chat Error Messages Async SDK Intro Create an Async Client Send Async Messages Use asyncio Run Parallel Requests Stream Async Text Handle Async Errors Set Async Timeouts Close Async Clients Choose Sync or Async Tool Use Intro Define a Tool Create Tool Schemas Send Tools to Claude Read Tool Calls Run Python Tools Return Tool Results Continue After Tool Use Control Tool Choice Handle Tool Errors Use the beta_tool Decorator Create a Tool Runner Add Tool Docstrings Validate Tool Inputs Use Multiple Tools Limit Tool Calls Log Tool Activity Build a Weather Tool Build a Search Tool Build a Calculator Tool Structured Output Intro Request JSON Data Validate JSON Output Use Pydantic Models Handle Invalid JSON Extract Fields from Text Generate Typed Data Use Image URLs Send Base64 Images Read PDFs with Claude Use Output Schemas Build Data Extraction Test Structured Responses Send Image Inputs Upload Files Use File IDs Process Text Files Summarize Documents Extract Table Data Handle File Errors Read Cache Usage Reduce Repeated Input Costs Debug Cache Misses Prompt Caching Intro Enable Prompt Caching Cache System Prompts Cache Long Context Test Cache Performance Use Cache Breakpoints Cache Best Practices Message Batches Intro Create a Message Batch Set Batch IDs Check Batch Status List Message Batches Get Batch Results Process Batch Outputs Handle Failed Batch Items Use Batches for Bulk Tasks Compare Batches and Requests Handle API Errors Handle Rate Limits Retry Failed Requests Set Request Timeouts Handle Network Errors Use Exponential Backoff Build Reliable API Calls Use Extended Thinking Log API Errors Track Request IDs Paginate API Results Set Thinking Budgets Read Thinking Blocks Use Tool Search Use Web Search Tools Use Computer Tools Use Citations Use Token Counting Read Raw Responses Set Custom Headers Use Claude on AWS Bedrock Use Claude on Vertex AI Use Claude on Microsoft Foundry Configure Cloud Credentials Choose a Cloud Provider Compare API Integrations Configure Provider Clients Handle Cloud Errors Use Cloud SDK Extras Deploy Cloud Apps Protect API Keys Use a .env File Ignore Secrets in Git Validate User Input Reduce Prompt Injection Limit Tool Permissions Avoid Unsafe Tool Calls Sanitize Tool Results Set Usage Limits Review Security Logs Test SDK Functions Mock API Responses Test Error Handling Test Streaming Code Measure Token Usage Track API Costs Configure Logging Deploy with Docker Deploy a FastAPI App Monitor Production Apps Build a Claude Chatbot Build a Text Summarizer Build a Code Explainer Build a JSON Extractor Build a PDF Assistant Build a Streaming Chat App Build a Tool-Calling Agent Build a Batch Processor Build a Research Assistant Build a Claude API Dashboard
Ask about this post
AI Ask about this post

Ask questions about Use Tool Search and get answers drawn from it.

Signed-in readers only.