Web Search Tools
Fresh data, cited and scrubbed
Live web access keeps answers current and sourced. Search tools add freshness and citations — and new failure modes: stale results, SEO junk, cost, and prompt-injectable page content.
What you will learn
- Add a search tool to a stack
- Ground answers with citations
- Filter junk and injected content
What is this?
A web search tool gives the model live snippets and URLs it reasons from. Good implementations restrict result counts, fetch only what is needed (or just the snippets), cite sources explicitly, and sanitize page text — because the web is adversarial and noisy.
Why do you need it?
- Recency beats weights for prices, events, breaking info.
- Sourced answers earn trust and auditability.
- Small, curated snippets keep token costs sane.
- Without citation, 'search' answers are indistinguishable from memories.
Mental model
A research intern with a timer
Search tool
Intern retrieves 5 short clippings, flags source and date of each, and hands you a tight summary — not a library dump. Your rules: sources cited, recency honored, no sketchy sites. The intern never sounds sure about a clipping they can't locate.
How it works
- Pick a backend: provider web tool or your own search API.
- Limit result count and snippet length; sort by relevance/recency.
- Return structured hits: title, URL, snippet, date.
- Ask the model to cite hit URLs in the answer.
- Sanitize fetched page text (strip scripts/injectables) if full-text reads occur.
Search round trip.
In production
- Support agents search internal wikis/products for current policy.
- News and market apps ground recency-driven answers with dates.
- Autonomous research loops chain multiple targeted searches.
Best practices
- Cap results (3-8); the tail is garbage.
- Require a source reference for each factual claim.
- Recency filter when the task is time-sensitive.
- Block known low-quality domains at the tool layer.
Common mistakes
- Feeding the model raw HTML or script text.
- No citation discipline — answers quote but don't link.
- Infinite search loops burning budget per turn.
Common issues
Hallucinated URLsNo citation constraint
Force URLs from the actual search results in the answer schema.
Prompt injection via page textFull-text fetch unfiltered
Fetch snippets only, or sanitize + treat page text as data.
Debugging tips
- Answers stale → recency sort missing or query too narrow.
- Junk-y answers → result cap high or domain blocklist absent.
- Citations unverifiable → require URL in the output schema.
Interview checkpoint
Quick quiz
A rule that improves search truthfulness:
Search results are always safe to feed straight to the model.