Loading...
    • Developer Guide
    • API Reference
    • MCP
    • Resources
    • Release Notes
    Search...
    ⌘K

    First steps

    Intro to ClaudeQuickstart

    Models & pricing

    Models overviewChoosing a modelWhat's new in Claude 4.5Migrating to Claude 4.5Model deprecationsPricing

    Build with Claude

    Features overviewUsing the Messages APIContext windowsPrompting best practices

    Capabilities

    Prompt cachingContext editingExtended thinkingStreaming MessagesBatch processingCitationsMultilingual supportToken countingEmbeddingsVisionPDF supportFiles APISearch resultsGoogle Sheets add-on

    Tools

    OverviewHow to implement tool useToken-efficient tool useFine-grained tool streamingBash toolCode execution toolComputer use toolText editor toolWeb fetch toolWeb search toolMemory tool

    Agent Skills

    OverviewQuickstartBest practicesUsing Skills with the API

    Agent SDK

    OverviewTypeScript SDKPython SDK

    Guides

    Streaming InputHandling PermissionsSession ManagementHosting the Agent SDKModifying system promptsMCP in the SDKCustom ToolsSubagents in the SDKSlash Commands in the SDKAgent Skills in the SDKTracking Costs and UsageTodo ListsPlugins in the SDK

    MCP in the API

    MCP connectorRemote MCP servers

    Claude on 3rd-party platforms

    Amazon BedrockVertex AI

    Prompt engineering

    OverviewPrompt generatorUse prompt templatesPrompt improverBe clear and directUse examples (multishot prompting)Let Claude think (CoT)Use XML tagsGive Claude a role (system prompts)Prefill Claude's responseChain complex promptsLong context tipsExtended thinking tips

    Test & evaluate

    Define success criteriaDevelop test casesUsing the Evaluation ToolReducing latency

    Strengthen guardrails

    Reduce hallucinationsIncrease output consistencyMitigate jailbreaksStreaming refusalsReduce prompt leakKeep Claude in character

    Administration and monitoring

    Admin API overviewUsage and Cost APIClaude Code Analytics API
    Console
    Capabilities

    Search results

    Enable natural citations for RAG applications by providing search results with source attribution

    Search result content blocks enable natural citations with proper source attribution, bringing web search-quality citations to your custom applications. This feature is particularly powerful for RAG (Retrieval-Augmented Generation) applications where you need Claude to cite sources accurately.

    The search results feature is available on the following models:

    • Claude Opus 4.1 (claude-opus-4-1-20250805)
    • Claude Opus 4 (claude-opus-4-20250514)
    • Claude Sonnet 4.5 (claude-sonnet-4-5-20250929)
    • Claude Sonnet 4 (claude-sonnet-4-20250514)
    • Claude Sonnet 3.7 (deprecated) (claude-3-7-sonnet-20250219)
    • Claude 3.5 Haiku (claude-3-5-haiku-20241022)

    Key benefits

    • Natural citations - Achieve the same citation quality as web search for any content
    • Flexible integration - Use in tool returns for dynamic RAG or as top-level content for pre-fetched data
    • Proper source attribution - Each result includes source and title information for clear attribution
    • No document workarounds needed - Eliminates the need for document-based workarounds
    • Consistent citation format - Matches the citation quality and format of Claude's web search functionality

    How it works

    Search results can be provided in two ways:

    1. From tool calls - Your custom tools return search results, enabling dynamic RAG applications
    2. As top-level content - You provide search results directly in user messages for pre-fetched or cached content

    In both cases, Claude can automatically cite information from the search results with proper source attribution.

    Search result schema

    Search results use the following structure:

    {
      "type": "search_result",
      "source": "https://example.com/article",  // Required: Source URL or identifier
      "title": "Article Title",                  // Required: Title of the result
      "content": [                               // Required: Array of text blocks
        {
          "type": "text",
          "text": "The actual content of the search result..."
        }
      ],
      "citations": {                             // Optional: Citation configuration
        "enabled": true                          // Enable/disable citations for this result
      }
    }

    Required fields

    FieldTypeDescription
    typestringMust be "search_result"
    sourcestringThe source URL or identifier for the content
    titlestringA descriptive title for the search result
    contentarrayAn array of text blocks containing the actual content

    Optional fields

    FieldTypeDescription
    citationsobjectCitation configuration with enabled boolean field
    cache_controlobjectCache control settings (e.g., {"type": "ephemeral"})

    Each item in the content array must be a text block with:

    • type: Must be "text"
    • text: The actual text content (non-empty string)

    Method 1: Search results from tool calls

    The most powerful use case is returning search results from your custom tools. This enables dynamic RAG applications where tools fetch and return relevant content with automatic citations.

    Example: Knowledge base tool

    from anthropic import Anthropic
    from anthropic.types import (
        MessageParam,
        TextBlockParam,
        SearchResultBlockParam,
        ToolResultBlockParam
    )
    
    client = Anthropic()
    
    # Define a knowledge base search tool
    knowledge_base_tool = {
        "name": "search_knowledge_base",
        "description": "Search the company knowledge base for information",
        "input_schema": {
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "The search query"
                }
            },
            "required": ["query"]
        }
    }
    
    # Function to handle the tool call
    def search_knowledge_base(query):
        # Your search logic here
        # Returns search results in the correct format
        return [
            SearchResultBlockParam(
                type="search_result",
                source="https://docs.company.com/product-guide",
                title="Product Configuration Guide",
                content=[
                    TextBlockParam(
                        type="text",
                        text="To configure the product, navigate to Settings > Configuration. The default timeout is 30 seconds, but can be adjusted between 10-120 seconds based on your needs."
                    )
                ],
                citations={"enabled": True}
            ),
            SearchResultBlockParam(
                type="search_result",
                source="https://docs.company.com/troubleshooting",
                title="Troubleshooting Guide",
                content=[
                    TextBlockParam(
                        type="text",
                        text="If you encounter timeout errors, first check the configuration settings. Common causes include network latency and incorrect timeout values."
                    )
                ],
                citations={"enabled": True}
            )
        ]
    
    # Create a message with the tool
    response = client.messages.create(
        model="claude-sonnet-4-5",  # Works with all supported models
        max_tokens=1024,
        tools=[knowledge_base_tool],
        messages=[
            MessageParam(
                role="user",
                content="How do I configure the timeout settings?"
            )
        ]
    )
    
    # When Claude calls the tool, provide the search results
    if response.content[0].type == "tool_use":
        tool_result = search_knowledge_base(response.content[0].input["query"])
        
        # Send the tool result back
        final_response = client.messages.create(
            model="claude-sonnet-4-5",  # Works with all supported models
            max_tokens=1024,
            messages=[
                MessageParam(role="user", content="How do I configure the timeout settings?"),
                MessageParam(role="assistant", content=response.content),
                MessageParam(
                    role="user",
                    content=[
                        ToolResultBlockParam(
                            type="tool_result",
                            tool_use_id=response.content[0].id,
                            content=tool_result  # Search results go here
                        )
                    ]
                )
            ]
        )

    Method 2: Search results as top-level content

    You can also provide search results directly in user messages. This is useful for:

    • Pre-fetched content from your search infrastructure
    • Cached search results from previous queries
    • Content from external search services
    • Testing and development

    Example: Direct search results

    from anthropic import Anthropic
    from anthropic.types import (
        MessageParam,
        TextBlockParam,
        SearchResultBlockParam
    )
    
    client = Anthropic()
    
    # Provide search results directly in the user message
    response = client.messages.create(
        model="claude-sonnet-4-5",
        max_tokens=1024,
        messages=[
            MessageParam(
                role="user",
                content=[
                    SearchResultBlockParam(
                        type="search_result",
                        source="https://docs.company.com/api-reference",
                        title="API Reference - Authentication",
                        content=[
                            TextBlockParam(
                                type="text",
                                text="All API requests must include an API key in the Authorization header. Keys can be generated from the dashboard. Rate limits: 1000 requests per hour for standard tier, 10000 for premium."
                            )
                        ],
                        citations={"enabled": True}
                    ),
                    SearchResultBlockParam(
                        type="search_result",
                        source="https://docs.company.com/quickstart",
                        title="Getting Started Guide",
                        content=[
                            TextBlockParam(
                                type="text",
                                text="To get started: 1) Sign up for an account, 2) Generate an API key from the dashboard, 3) Install our SDK using pip install company-sdk, 4) Initialize the client with your API key."
                            )
                        ],
                        citations={"enabled": True}
                    ),
                    TextBlockParam(
                        type="text",
                        text="Based on these search results, how do I authenticate API requests and what are the rate limits?"
                    )
                ]
            )
        ]
    )
    
    print(response.model_dump_json(indent=2))

    Claude's response with citations

    Regardless of how search results are provided, Claude automatically includes citations when using information from them:

    {
      "role": "assistant",
      "content": [
        {
          "type": "text",
          "text": "To authenticate API requests, you need to include an API key in the Authorization header",
          "citations": [
            {
              "type": "search_result_location",
              "source": "https://docs.company.com/api-reference",
              "title": "API Reference - Authentication",
              "cited_text": "All API requests must include an API key in the Authorization header",
              "search_result_index": 0,
              "start_block_index": 0,
              "end_block_index": 0
            }
          ]
        },
        {
          "type": "text",
          "text": ". You can generate API keys from your dashboard",
          "citations": [
            {
              "type": "search_result_location",
              "source": "https://docs.company.com/api-reference",
              "title": "API Reference - Authentication",
              "cited_text": "Keys can be generated from the dashboard",
              "search_result_index": 0,
              "start_block_index": 0,
              "end_block_index": 0
            }
          ]
        },
        {
          "type": "text",
          "text": ". The rate limits are 1,000 requests per hour for the standard tier and 10,000 requests per hour for the premium tier.",
          "citations": [
            {
              "type": "search_result_location",
              "source": "https://docs.company.com/api-reference",
              "title": "API Reference - Authentication",
              "cited_text": "Rate limits: 1000 requests per hour for standard tier, 10000 for premium",
              "search_result_index": 0,
              "start_block_index": 0,
              "end_block_index": 0
            }
          ]
        }
      ]
    }

    Citation fields

    Each citation includes:

    FieldTypeDescription
    typestringAlways "search_result_location" for search result citations
    sourcestringThe source from the original search result
    titlestring or nullThe title from the original search result
    cited_textstringThe exact text being cited
    search_result_indexintegerIndex of the search result (0-based)
    start_block_indexintegerStarting position in the content array
    end_block_indexintegerEnding position in the content array

    Note: The search_result_index refers to the index of the search result content block (0-based), regardless of how the search results were provided (tool call or top-level content).

    Multiple content blocks

    Search results can contain multiple text blocks in the content array:

    {
      "type": "search_result",
      "source": "https://docs.company.com/api-guide",
      "title": "API Documentation",
      "content": [
        {
          "type": "text",
          "text": "Authentication: All API requests require an API key."
        },
        {
          "type": "text",
          "text": "Rate Limits: The API allows 1000 requests per hour per key."
        },
        {
          "type": "text",
          "text": "Error Handling: The API returns standard HTTP status codes."
        }
      ]
    }

    Claude can cite specific blocks using the start_block_index and end_block_index fields.

    Advanced usage

    Combining both methods

    You can use both tool-based and top-level search results in the same conversation:

    # First message with top-level search results
    messages = [
        MessageParam(
            role="user",
            content=[
                SearchResultBlockParam(
                    type="search_result",
                    source="https://docs.company.com/overview",
                    title="Product Overview",
                    content=[
                        TextBlockParam(type="text", text="Our product helps teams collaborate...")
                    ],
                    citations={"enabled": True}
                ),
                TextBlockParam(
                    type="text",
                    text="Tell me about this product and search for pricing information"
                )
            ]
        )
    ]
    
    # Claude might respond and call a tool to search for pricing
    # Then you provide tool results with more search results

    Combining with other content types

    Both methods support mixing search results with other content:

    # In tool results
    tool_result = [
        SearchResultBlockParam(
            type="search_result",
            source="https://docs.company.com/guide",
            title="User Guide",
            content=[TextBlockParam(type="text", text="Configuration details...")],
            citations={"enabled": True}
        ),
        TextBlockParam(
            type="text",
            text="Additional context: This applies to version 2.0 and later."
        )
    ]
    
    # In top-level content
    user_content = [
        SearchResultBlockParam(
            type="search_result",
            source="https://research.com/paper",
            title="Research Paper",
            content=[TextBlockParam(type="text", text="Key findings...")],
            citations={"enabled": True}
        ),
        {
            "type": "image",
            "source": {"type": "url", "url": "https://example.com/chart.png"}
        },
        TextBlockParam(
            type="text",
            text="How does the chart relate to the research findings?"
        )
    ]

    Cache control

    Add cache control for better performance:

    {
      "type": "search_result",
      "source": "https://docs.company.com/guide",
      "title": "User Guide",
      "content": [{"type": "text", "text": "..."}],
      "cache_control": {
        "type": "ephemeral"
      }
    }

    Citation control

    By default, citations are disabled for search results. You can enable citations by explicitly setting the citations configuration:

    {
      "type": "search_result",
      "source": "https://docs.company.com/guide",
      "title": "User Guide",
      "content": [{"type": "text", "text": "Important documentation..."}],
      "citations": {
        "enabled": true  // Enable citations for this result
      }
    }

    When citations.enabled is set to true, Claude will include citation references when using information from the search result. This enables:

    • Natural citations for your custom RAG applications
    • Source attribution when interfacing with proprietary knowledge bases
    • Web search-quality citations for any custom tool that returns search results

    If the citations field is omitted, citations are disabled by default.

    Citations are all-or-nothing: either all search results in a request must have citations enabled, or all must have them disabled. Mixing search results with different citation settings will result in an error. If you need to disable citations for some sources, you must disable them for all search results in that request.

    Best practices

    For tool-based search (Method 1)

    • Dynamic content: Use for real-time searches and dynamic RAG applications
    • Error handling: Return appropriate messages when searches fail
    • Result limits: Return only the most relevant results to avoid context overflow

    For top-level search (Method 2)

    • Pre-fetched content: Use when you already have search results
    • Batch processing: Ideal for processing multiple search results at once
    • Testing: Great for testing citation behavior with known content

    General best practices

    1. Structure results effectively

      • Use clear, permanent source URLs
      • Provide descriptive titles
      • Break long content into logical text blocks
    2. Maintain consistency

      • Use consistent source formats across your application
      • Ensure titles accurately reflect content
      • Keep formatting consistent
    3. Handle errors gracefully

      def search_with_fallback(query):
          try:
              results = perform_search(query)
              if not results:
                  return {"type": "text", "text": "No results found."}
              return format_as_search_results(results)
          except Exception as e:
              return {"type": "text", "text": f"Search error: {str(e)}"}

    Limitations

    • Search result content blocks are available on Claude API and Google Cloud's Vertex AI
    • Only text content is supported within search results (no images or other media)
    • The content array must contain at least one text block
    • Key benefits
    • How it works
    • Search result schema
    • Required fields
    • Optional fields
    • Method 1: Search results from tool calls
    • Example: Knowledge base tool
    • Method 2: Search results as top-level content
    • Example: Direct search results
    • Claude's response with citations
    • Citation fields
    • Multiple content blocks
    • Advanced usage
    • Combining both methods
    • Combining with other content types
    • Cache control
    • Citation control
    • Best practices
    • For tool-based search (Method 1)
    • For top-level search (Method 2)
    • General best practices
    • Limitations
    © 2025 ANTHROPIC PBC

    Products

    • Claude
    • Claude Code
    • Max plan
    • Team plan
    • Enterprise plan
    • Download app
    • Pricing
    • Log in

    Features

    • Claude and Slack
    • Claude in Excel

    Models

    • Opus
    • Sonnet
    • Haiku

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Claude Developer Platform

    • Overview
    • Developer docs
    • Pricing
    • Amazon Bedrock
    • Google Cloud’s Vertex AI
    • Console login

    Learn

    • Blog
    • Catalog
    • Courses
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Help and security

    • Availability
    • Status
    • Support center

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy

    Products

    • Claude
    • Claude Code
    • Max plan
    • Team plan
    • Enterprise plan
    • Download app
    • Pricing
    • Log in

    Features

    • Claude and Slack
    • Claude in Excel

    Models

    • Opus
    • Sonnet
    • Haiku

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Claude Developer Platform

    • Overview
    • Developer docs
    • Pricing
    • Amazon Bedrock
    • Google Cloud’s Vertex AI
    • Console login

    Learn

    • Blog
    • Catalog
    • Courses
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Help and security

    • Availability
    • Status
    • Support center

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    © 2025 ANTHROPIC PBC