AI applications are becoming increasingly useful for answering questions that require current information. With web search integration, a language model can retrieve information from external sources and use it to generate a response.

However, there is an important design challenge that developers should not overlook: retrieved information and AI-generated explanations are not the same thing.

A search result contains information retrieved from a source. An AI-generated answer is the model's interpretation of that information. If an application combines both into one block of text without preserving their relationship, users may find it difficult to understand which information came from a source and which parts were generated by the model.

This becomes particularly important in applications that provide technical documentation, financial information, product comparisons, research summaries, or security recommendations.

Amazon Bedrock Web Search returns source citation annotations with generated responses. Developers can use these annotations to preserve source information and display it separately from the generated answer.

In this article, we will explore how to design this separation in a C# application using ASP.NET Core and Amazon Bedrock.

Why Search Results and AI-Generated Answers Should Be Separate

Consider an application that answers questions about the latest .NET release.

A user asks:

"What are the important changes in the latest .NET release?"

The application performs a web search and retrieves information from official documentation and technical articles.

The model then generates a response explaining the changes in simple language.

The response may contain several different types of information:

  • Information directly supported by retrieved sources.
  • Explanations generated by the model.
  • Comparisons based on multiple sources.
  • Recommendations created by the model.
  • Additional context based on the model's existing knowledge.

If the application displays everything as one paragraph, users cannot easily distinguish these categories.

For example, suppose the model generates this response:

"The latest release introduces improvements to application performance. Developers should also consider updating their existing packages before upgrading production services."

The first statement may be supported by an official release document. The second may be a general recommendation generated by the model.

Both statements may be useful, but they do not necessarily have the same source.

A better application design preserves the generated answer and its source citations as separate pieces of information.

Understand How Amazon Bedrock Returns Citations

Amazon Bedrock Web Search integrates with the Responses API.

When a supported model uses Web Search, the response contains generated text and URL citation annotations.

The annotations provide information such as:

  • Source title.
  • Source URL.
  • Starting position of the cited text.
  • Ending position of the cited text.

A simplified response structure looks like this:

JSON
{
  "output": [
    {
      "type": "message",
      "content": [
        {
          "type": "output_text",
          "text": "The latest release introduces several improvements.",
          "annotations": [
            {
              "type": "url_citation",
              "title": "Official Release Documentation",
              "url": "https://example.com/release",
              "start_index": 0,
              "end_index": 65
            }
          ]
        }
      ]
    }
  ]
}

The example is illustrative. The actual response can contain multiple output items, content blocks, and annotations.

The important detail is that citations are attached to the generated text rather than returned as an unrelated list of search results.

This allows the application to understand which part of the generated response is associated with a particular source.

It is also important to understand what a citation does not tell you. A citation can be based on a Search observation even when Fetch did not retrieve the complete page. Therefore, the presence of a citation does not prove that the full source document was fetched or independently verified.

Design a Separate Response Model

Before writing the parsing logic, define how the application should represent the answer.

Instead of returning a single string from the AI service, create a response model that contains the generated answer and a separate collection of sources.

For example:

C#
public class AIAnswerResponse
{
    public string Answer { get; set; } = string.Empty;

    public List<SourceReference> Sources { get; set; } = new();
}

public class SourceReference
{
    public string Title { get; set; } = string.Empty;

    public string Url { get; set; } = string.Empty;

    public int StartIndex { get; set; }

    public int EndIndex { get; set; }
}

This structure gives the application two responsibilities:

  • Answer contains the text generated by the model.
  • Sources contains the references returned through citation annotations.

Keeping these properties separate makes the API easier to consume from web, mobile, and desktop clients.

It also prevents the frontend from having to interpret the original Amazon Bedrock response format.

Extract Generated Text and Citations in C#

Let's create a service that reads the Responses API output and extracts the generated text and source annotations.

The following example assumes that the application has already received a successful response from Amazon Bedrock.

C#
using System.Text.Json;

public static class BedrockResponseParser
{
    public static AIAnswerResponse Parse(string responseBody)
    {
        using var document = JsonDocument.Parse(responseBody);

        var result = new AIAnswerResponse();

        var root = document.RootElement;

        if (!root.TryGetProperty("output", out var output))
        {
            return result;
        }

        foreach (var item in output.EnumerateArray())
        {
            if (!item.TryGetProperty("type", out var itemType) ||
                itemType.GetString() != "message")
            {
                continue;
            }

            if (!item.TryGetProperty("content", out var content))
            {
                continue;
            }

            foreach (var block in content.EnumerateArray())
            {
                if (!block.TryGetProperty("type", out var blockType) ||
                    blockType.GetString() != "output_text")
                {
                    continue;
                }

                if (block.TryGetProperty("text", out var text))
                {
                    result.Answer += text.GetString();
                }

                if (!block.TryGetProperty(
                    "annotations", out var annotations))
                {
                    continue;
                }

                foreach (var annotation in annotations.EnumerateArray())
                {
                    if (!annotation.TryGetProperty(
                        "type", out var annotationType) ||
                        annotationType.GetString() != "url_citation")
                    {
                        continue;
                    }

                    var source = new SourceReference
                    {
                        Title = annotation.TryGetProperty(
                            "title", out var title)
                                ? title.GetString() ?? string.Empty
                                : string.Empty,

                        Url = annotation.TryGetProperty(
                            "url", out var url)
                                ? url.GetString() ?? string.Empty
                                : string.Empty,

                        StartIndex = annotation.TryGetProperty(
                            "start_index", out var start)
                                ? start.GetInt32()
                                : 0,

                        EndIndex = annotation.TryGetProperty(
                            "end_index", out var end)
                                ? end.GetInt32()
                                : 0
                    };

                    result.Sources.Add(source);
                }
            }
        }

        return result;
    }
}

This parser performs two operations.

First, it extracts the generated text from output_text blocks.

Second, it reads the url_citation annotations and stores the source details separately.

The application can now return a structured response without losing the citation information.

For a production implementation, consider using dedicated response DTOs and System.Text.Json deserialization instead of manually traversing JsonDocument. Also validate annotation positions and URLs before using them in the frontend.

Return a Structured Response From ASP.NET Core

Once the parser is ready, the controller can return the answer and sources as separate properties.

For example:

C#
[ApiController]
[Route("api/ai")]
public class AIController : ControllerBase
{
    private readonly BedrockSearchService _searchService;

    public AIController(BedrockSearchService searchService)
    {
        _searchService = searchService;
    }

    [HttpPost("ask")]
    public async Task<IActionResult> Ask(
        [FromBody] AskRequest request,
        CancellationToken cancellationToken)
    {
        if (string.IsNullOrWhiteSpace(request.Question))
        {
            return BadRequest("Question is required.");
        }

        var result = await _searchService.AskAsync(
            request.Question,
            cancellationToken);

        return Ok(result);
    }
}

The service should return AIAnswerResponse rather than a plain string.

The resulting API response could look like this:

JSON
{
  "answer": "The latest release includes several performance improvements.",
  "sources": [
    {
      "title": "Official Release Documentation",
      "url": "https://example.com/release",
      "startIndex": 0,
      "endIndex": 72
    },
    {
      "title": "Performance Improvements",
      "url": "https://example.com/performance",
      "startIndex": 0,
      "endIndex": 72
    }
  ]
}

The URLs and citation positions are illustrative.

The frontend can now display the generated answer in its main response area and render the source links in a separate section.

Display Sources Without Mixing Them With the Answer

The frontend should make it easy for users to identify the generated response and inspect its sources.

A simple interface might contain:

Code
AI Answer

The latest release includes improvements to runtime
performance and application development.

Sources

Official Release Documentation
Performance Improvements

For more advanced applications, citations can appear inline near the statements they support, with a separate source panel for the complete list.

There are two common presentation approaches.

PresentationWhen to use it
Separate source panelGeneral question-answering applications
Inline citationsResearch tools and technical documentation assistants

Inline citations are particularly useful when an answer contains several claims supported by different sources.

The citation positions can help the frontend associate source references with the corresponding text. However, developers should verify the indexing convention and handle Unicode text carefully when mapping those positions to frontend string offsets.

Do not simply append every source URL to the end of the answer without considering which statements the sources support.

Avoid Treating Every AI Statement as a Verified Fact

Separating citations is only part of the solution.

A citation does not automatically prove that every statement in the generated answer is accurate.

Consider a response that contains three claims:

  • A feature was introduced in a particular release.
  • The feature improves application performance.
  • Developers should use it in every production application.

The first claim might be supported by official release documentation. The second may require benchmark evidence. The third is a recommendation that depends on the application's requirements.

One source should not automatically be treated as evidence for all three claims.

For applications that require higher confidence, consider adding an instruction to the model that encourages it to:

  • Use retrieved information for current factual claims.
  • Avoid inventing source details.
  • Clearly identify recommendations as recommendations.
  • Mention when available sources do not support a conclusion.
  • Avoid presenting uncertain information as confirmed fact.

These instructions improve response quality, but they are not a substitute for independent validation.

For critical information, applications should apply additional verification rules before presenting the result to users.

Handle Missing Sources and Search Failures

A production application must also handle situations where the model cannot find useful information.

For example, a user might ask about a recently announced feature that has not yet appeared in the search index.

The model may return an answer with no citations, or it may indicate that the available information is insufficient.

Your application should not generate artificial source links just to make the response look complete.

A sensible response-handling strategy includes:

  • Display the generated answer when it is available.
  • Show a sources section only when citations exist.
  • Clearly indicate when no sources were returned.
  • Handle unsuccessful API requests separately from successful responses.
  • Avoid treating an HTTP 200 response as proof that every search and fetch operation succeeded.

If an application requires every factual answer to have supporting citations, implement that requirement as an application-level validation rule. Do not assume that enabling Web Search guarantees that every generated sentence will have a citation.

Security and Source Validation

Source URLs come from external information and should be treated as untrusted input.

Before displaying them in a web application:

  • Allow only HTTP and HTTPS URLs.
  • Encode titles and other text before rendering them.
  • Use safe link attributes when opening links in a new browser tab.
  • Avoid executing HTML returned as search content.
  • Do not treat a source URL as permission to access internal network resources.
  • Apply appropriate content security policies.

For applications using Amazon Bedrock Web Search, also retain and display the source citations and links when presenting outputs that incorporate Search Results to end users.

Review the acceptable-use requirements before building additional storage or indexing workflows around retrieved content.

Summary

Keeping web search results separate from AI-generated answers makes an AI application easier to understand, maintain, and trust.

Amazon Bedrock Web Search returns generated text with URL citation annotations. Developers can extract these annotations, preserve the source title and URL, and return them separately through their own API response models.

The frontend can then display the answer and its sources independently or use inline citations to show which references support particular statements.

The most important lesson is that retrieved information, generated explanations, and application recommendations should not be treated as interchangeable. Preserving their relationships gives users a clearer understanding of where information came from and how much confidence they should place in the answer.