Topic 2 of 4 · 5 min read
Grounding answers with hosted web search
Goal: Configure hosted web search with domain and usage limits and check that the answer's citations support its claims.
Hosted web search lets the model look things up, and you control it with three settings: which domains it may use, how many searches it may run, and how you check the citations it returns.
Check yourself · 1 of 3
What does max_uses on a hosted web search tool control?
Why it matters
A model's training data has a cutoff, and it will answer questions about prices, versions and news from memory if you let it. Hosted search grounds the answer in live pages. Grounding only helps if the sources are good, the cost is bounded, and the answer actually says what its sources say.
How to configure it
- Add the tool to
tools. With Claude it isweb_search; OpenAI and Gemini offer the same idea under their own names. - Limit domains. Use
allowed_domainsto search only trusted sites, orblocked_domainsto exclude some. Claude accepts one of the two per request, not both, and returns a 400 if you send both. Entries are bare domains likedocs.example.com, without a scheme. - Cap searches.
max_useslimits searches in a turn. A simple fact question usually needs one to three; comparative research can use ten or more. When the cap is hit, the result block carries amax_uses_exceedederror. Failed searches count against the cap. - Budget the price. On the Claude API search costs $10 per 1,000 searches, plus tokens for the results. Five searches per request at 20,000 requests a day is 100,000 searches, or about $1,000 a day before tokens.
- Pass results back intact. In multi-turn chats, send the assistant blocks back unchanged, including
encrypted_content.
tools = [{
"type": "web_search_20250305",
"name": "web_search",
"max_uses": 3,
"allowed_domains": ["docs.python.org", "peps.python.org"],
}]
Check the citations
Each cited claim carries a web_search_result_location with url, title and cited_text. Citations prove where text came from, not that the answer reads it right. Spot-check that cited_text supports the sentence beside it. If you show the output to users, show the sources too.
Before and after
Weak: no limits, and the app prints the answer only. A forum post and a blog become "sources" for a legal question, and nobody can see them.
Better: allowed_domains set to the regulator's site, max_uses: 3, and the answer rendered with linked citations. A reviewer can click each source.
What goes wrong
- Citing without reading. A link next to a sentence does not mean the page says it.
- No cap. A broad question can run many searches and a large bill.
- Both domain lists. Sending allowed and blocked together returns an error.
- Stale answers anyway. Allowed domains may carry old pages. Check dates for fast-changing facts.
Examples
Pricing a feature
A help bot averages 2 searches per question and gets 10,000 questions a day. That is 20,000 searches a day, about $200 at $10 per 1,000, before tokens. Setting max_uses: 2 makes this the ceiling instead of the average.
A citation that does not support the claim
The answer says "the limit is 500 requests per minute" and cites a pricing page. The cited_text mentions 500 requests per day. The link is real and the claim is wrong. Only reading cited_text catches it.
Key points
- Use allowed_domains or blocked_domains, never both, to control which sites the model may read.
- max_uses caps searches per turn, and failed searches still count against it.
- Search is billed per search plus tokens for results, so multiply searches per request by traffic before launch.
- A citation shows the source of a claim; you still have to check that the cited text supports it.
- Send assistant blocks back unchanged in multi-turn chats so encrypted search content survives.
Common mistakes
- Adding search with no domain list for a question that needs official sources.
- Leaving max_uses unset and learning the cost from the invoice.
- Treating a citation's presence as proof the claim is right.
- Rewriting or trimming the citations before showing the answer to users.
Check yourself · 2 of 3
You want search restricted to your docs site and your partner's site. What is valid?
Check yourself · 3 of 3
An answer cites a page, but you want to know whether it is supported. What do you check?
Practice items, not counted towards your mastery.
Start here
- Web search tool (Claude docs) (opens in a new tab)DocsFree
Parameters, response blocks, citations and the $10 per 1,000 searches price.
- Code execution tool (Claude docs) (opens in a new tab)DocsFree
Container limits, file upload, result blocks and error codes.
- Server tools (Claude API docs) (opens in a new tab)DocsFree
How server_tool_use blocks, pause_turn and domain filtering work for provider-run tools.
More for this topic
- Web search guide (OpenAI docs) (opens in a new tab)DocsFree
The same idea from another vendor: a hosted search tool with citations in the response.