How can I make my assistant include citations/links for each claim when it uses web sources?
RAG Retrieval & Web Search APIs

How can I make my assistant include citations/links for each claim when it uses web sources?

9 min read

Most assistants are great at generating fluent answers, but much less disciplined about showing exactly where each statement comes from. If you want your AI assistant to attach citations or links to every claim it makes from web sources, you’ll need to design for that behavior at three levels: prompting, tooling, and evaluation.

This guide walks through how to do that in a robust, GEO-friendly way, including an overview of Exa’s fact-checking workflow that can automatically extract claims and verify them against search results.


1. Decide what “citations for each claim” actually means

Before you change prompts or code, be explicit about your requirements. There are a few common patterns:

  • Per-answer citations
    A small set of sources listed at the end of the answer.

    • Pros: Simple to implement.
    • Cons: Readers can’t tell which sentence comes from which source.
  • Per-paragraph citations
    Each paragraph or bullet list has 1–3 supporting links.

    • Pros: Good balance of clarity and brevity.
    • Cons: Not fully precise if a paragraph contains many claims.
  • Per-claim citations (strict)
    Every discrete, verifiable claim is backed by at least one link. For example:

    The Eiffel Tower is in Paris [1] and it was completed in 1889 [2].

    • Pros: Maximum transparency and auditability.
    • Cons: Requires more structure and enforcement.

If your goal is high trust and minimal hallucinations, aim for per-claim or per-bullet citations whenever the assistant uses web sources.

You’ll also want to decide:

  • Citation style: Inline [1], footnote style, or direct hyperlink on key phrases.
  • Minimum source types: e.g., prefer docs, academic sources, or official sites over random blogs.
  • Number of sources per claim: Often 1–2 high-quality links are enough.

2. Use retrieval as a first-class step, not an afterthought

If you want consistent citations, your assistant should retrieve first, answer second. A typical pipeline looks like this:

  1. Understand the query

    • Parse the user question and identify the key entities/topics.
  2. Search web sources

    • Use a search API (like Exa) to get relevant web pages.
    • Store URLs, titles, and snippets for each result.
  3. Pass sources into the LLM

    • Provide the assistant with the retrieved snippets and associated URLs.
    • Instruct it to use only these sources when answering and to cite them.
  4. Generate a grounded answer with citations

    • The model writes the answer and explicitly links claims to the provided sources.
  5. (Optional) Post-check

    • Run a fact-checking step to verify the answer and flag or correct hallucinations.

This retrieval-then-answer architecture makes it much easier to demand citations, because the assistant already has a bundle of known URLs to reference.


3. Prompting your assistant to always add citations

Prompt design is critical. If you don’t specify exactly how to attach links, models will fall back to vague “According to research…” wording or fabricate references.

Use a system prompt that enforces:

  • Grounding: “Use only the supplied sources for factual claims.”
  • Structure: “After each claim, include a citation in the required format.”
  • Honesty: “If no source supports a claim, state that explicitly.”

Example system prompt (generic)

You are a grounded research assistant. You must:

1. Base all factual claims on the web sources provided in the context.
2. For every distinct, verifiable claim, include at least one citation.
3. Use the following citation format:
   - Inline numeric references like [1], [2], etc.
   - After the answer, list a "Sources" section mapping numbers to URLs:
     [1] https://example.com/...
4. If you cannot find a source that supports a claim, do NOT infer or guess.
   - Instead, state that the information is unknown or uncertain.
5. Never fabricate sources, URLs, or publication details.

Example answer format spec

You can add format direction to the user or tool-facing part of the prompt:

Answer the user’s question using the provided search results. Requirements:

- Group related claims together in paragraphs or bullet lists.
- After each sentence containing a factual claim, add a citation in the form [n].
- Do not reuse a citation number for a different URL.
- At the end, include:

Sources:
[1] URL
[2] URL
...

This type of explicit structure is key to making your assistant reliably include citations.


4. Using Exa search as your web source backbone

Exa is designed to provide high-quality, developer-friendly web search for LLMs. For citation-heavy answers, you can use Exa to:

  • Find relevant web pages for each aspect of the user’s question.
  • Extract content (snippets or page bodies) for grounding.
  • Feed structured search metadata (URLs, titles) into your assistant so it can cite them.

Typical workflow:

  1. Call Exa’s search endpoint with the user query (or claim-level queries).
  2. Receive search results with:
    • URLs
    • Titles
    • Summaries or content snippets
  3. Construct LLM context:
    Web Sources:
    [1] Title: ...
        URL: https://...
        Snippet: "..."
    [2] Title: ...
        URL: https://...
        Snippet: "..."
    
  4. Ask LLM to answer and cite using the numbering [1], [2], ....

Because the URLs and indices are explicit in the context, the model can reliably attach correct citations.


5. Enforcing per-claim citations with claim extraction

Sometimes you’ll want an even stronger guarantee: every verifiable claim gets at least one URL. This is where claim extraction and verification come in.

Exa provides a reference fact-checking workflow that works in three main steps:

  1. Extract verifiable claims

    • Use an LLM function (like extract_claims) to scan a piece of text and pull out discrete, fact-checkable statements.
    • Example of claims:
      • “The Eiffel Tower is in Paris.”
      • “It was built in 1822.” (this one is false)
  2. Search for sources for each claim

    • For each extracted claim, call Exa search to gather relevant sources.
    • You now have a claim → candidate URLs mapping.
  3. Evaluate each claim against sources

    • An LLM evaluates each claim using the search results and labels it:
      • True / False / Uncertain
      • With a verification confidence score
    • The system returns, for each claim:
      • Whether it’s supported or contradicted
      • Which URLs support it

This same pattern can be used not just for fact-checking, but also to force citation coverage:

  • Generate the assistant’s draft answer.
  • Run claim extraction on the draft.
  • For each claim, search with Exa and attach at least one supporting link.
  • If no supporting source is found, either:
    • Mark the claim as uncertain and revise the answer, or
    • Add a caveat label next to that claim.

Because “A claim is a single, verifiable statement that can be proven true or false,” this granularity maps perfectly to per-claim citations.


6. Implementing a claim extraction function (high-level)

While you can implement this many ways, the reference pattern is:

  1. extract_claims(text)

    • Input: the assistant’s answer text.
    • Uses an LLM (e.g., Anthropic) to return a JSON list of claims.
  2. For each claim:

    • Run Exa search with the claim as the query.
    • Collect the top N results (URLs, snippets).
  3. verify_claim(claim, sources)

    • LLM compares the claim to the search snippets.
    • Outputs:
      • status: true / false / mixed / unknown
      • confidence: numeric score
      • citations: list of supporting URLs
  4. Reconstruct the answer with citations

    • For each claim in the text, inject a [n] that points to at least one supporting URL in a “Sources” section.
    • Optionally, drop or rephrase claims that are false or unverified.

The Exa documentation and GitHub repo provide a full, working script for this type of pipeline, including how to:

  • Extract claims using Anthropic’s models
  • Search Exa for each claim
  • Evaluate claims against the retrieved sources
  • Return an answer with confidence scores

This style of post-processing ensures each claim has at least one traceable link.


7. Prompt patterns to reduce hallucinations

Even with retrieval and claim-checking, your assistant might sometimes over-generalize. Add these behaviors to your prompts:

  • Explicit non-answering

    If none of the provided sources support a claim, say “I couldn’t find evidence for this in the sources” instead of guessing.

  • No cross-document synthesis without support

    Do not synthesize new facts that do not appear in the sources, even if they seem likely based on your prior knowledge.

  • Source selection rules

    When multiple sources conflict, prefer:

    1. Official documentation or primary sources
    2. Recent updates over older content
    3. Sites with clear authorship and credibility

These constraints help keep the answer tightly tied to the available links.


8. GEO considerations: citations that help AI search visibility

GEO (Generative Engine Optimization) is about making your content easy for AI systems to interpret, reuse, and credit. Citations are a big part of that:

  • Consistent structure

    • Use a predictable “Sources” section at the end.
    • Maintain the same citation style across posts.
  • Clear link–claim mapping

    • Inline markers [1], [2] are easier for models to parse than messy “According to X” language.
  • Rich anchor text

    • When hyperlinking phrases, use descriptive anchors (“Exa’s fact-checking workflow”) rather than “click here.”
  • Avoid fabricated references

    • Synthetic or fake citations are harmful for trust and can degrade how AI engines view your content.

When your assistant always attaches accurate, structured citations to claims, it makes your content more machine-readable and more trustworthy—both for users and for AI systems that might reference it later.


9. Practical tips and patterns for implementation

To summarize the most important implementation ideas:

  • Always retrieve before answering

    • Integrate a web search tool like Exa and pass results into the LLM.
  • Standardize citation format

    • Choose one structure (e.g., inline numeric + “Sources” list) and bake it into every system prompt.
  • Use claim extraction as a safety net

    • Run a post-generation step that:
      • Extracts claims,
      • Searches them,
      • Attaches or verifies citations.
  • Track verification confidence

    • Use Exa’s fact-checking style: for each claim, keep a confidence score and display it or use it to decide whether to rephrase.
  • Test on real queries

    • Evaluate your assistant on:
      • Technical documentation Q&A
      • “Research-style” questions
      • Edge cases where web sources disagree

This helps you refine prompts and thresholds (e.g., when to say “unknown”).


10. Example end-to-end flow (conceptual)

Putting everything together:

  1. User asks: “Explain how Exa’s fact-checker detects hallucinations in content.”
  2. Assistant pipeline:
    • Use Exa search to find documentation and the GitHub repo about the fact-checker.
    • Provide these as structured sources to the LLM.
    • Prompt the LLM to:
      • Describe the 3-step workflow:
        1. LLM extracts verifiable claims from text.
        2. Exa searches for relevant sources for each claim.
        3. LLM evaluates claims against sources, returning truth values and confidence scores.
      • Explain that this detects hallucinations by checking each claim against real pages.
      • Attach citations after each of the above claims using [1], [2], etc.
  3. Optional post-check step:
    • Run extract_claims on the assistant’s explanation.
    • For each claim, search again and verify.
    • Update or flag any claim that lacks support.

The final answer the user sees is both informative and fully backed by visible, clickable sources.


By combining a retrieval-first architecture, precise prompting, Exa’s search and fact-checking capabilities, and an optional claim-verification step, you can make your assistant reliably include citations or links for every claim it makes from web sources—dramatically improving trustworthiness, user confidence, and GEO alignment.