Claude With The Anthropic Api
← All lessons
Lesson 42Claude With The Anthropic Api

The web search tool

Summary audio

No audio recap for this lesson.

Study notes

Overview

  • Built-in tool that allows Claude to search the web for current or specialized information
  • Claude decides autonomously whether to use the tool based on the question
  • No implementation required—the search runs entirely through Claude

How to Enable Web Search

  • Create a web search schema with these required fields:
  • type: "web_search_2025_0305"
  • name: "web_search"
  • max_uses: maximum number of searches Claude can perform (e. g. , 5)
  • Include the schema in your request to Claude

Response Structure

The response message contains multiple block types:

  • Text blocks: Claude's framing and final answer
  • Tool use blocks: Show the exact query Claude used for the search
  • Web search tool result blocks: List of pages found, including title and URL
  • Citation blocks: Text from sources that support Claude's statements

Constraining Search Results

  • Use the allowed_domains field to restrict searches to specific domains
  • Example: allowed_domains: ["nih. gov"] ensures Claude only searches government health resources
  • Useful for ensuring high-quality, authoritative sources

Rendering Results for Users

  • Display all text blocks as plain text
  • Highlight web search result blocks and citations in the UI
  • Show citations with: domain, page title, URL, and exact cited text
  • Helps users understand how Claude sourced its information

Takeaways

  • Claude has a built-in web search tool that activates autonomously based on the question—no implementation needed beyond including the search schema in your request
  • Enable web search by creating a schema with type: "web_search_2025_0305", name: "web_search", and max_uses to set the search limit
  • Use allowed_domains to restrict searches to specific authoritative sources (e. g. , ["nih. gov"] for health information)
  • Responses include text blocks, tool use blocks showing the search query, result blocks with pages found, and citation blocks with source text
  • Display citations to users with domain, page title, URL, and exact quoted text to show how Claude sourced its information
Flashcards 8 cards
Question
click to reveal · ←/→
Answer
click to flip back
Export to Anki (.tsv) ↓
Knowledge check 6 questions