Tool Use
Intermediate 12 min read Tool Use

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.

web searchsearch toolcitationsfreshnessseogrounding
Prerequisites: Tool Use Overview
Before we start

What you will learn

  • Add a search tool to a stack
  • Ground answers with citations
  • Filter junk and injected content
Introduction

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.

Motivation

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.
Think about it

Mental model

Imagine

A research intern with a timer

Think of

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.

Mechanics

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.

Query
Fetch
Filter
Synthesize
Real world

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.
Guidelines

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.
Watch out

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.
Root cause analysis

Common issues

Error
Hallucinated URLs
Root cause

No citation constraint

Fix

Force URLs from the actual search results in the answer schema.

Error
Prompt injection via page text
Root cause

Full-text fetch unfiltered

Fix

Fetch snippets only, or sanitize + treat page text as data.

When things break

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.
Interviews

Interview checkpoint

Test yourself

Quick quiz

0/2
1

A rule that improves search truthfulness:

2

Search results are always safe to feed straight to the model.

Go deeper

Official documentation