Skip to content
Free$1 of credit for every new organization
All articles

Guide

Citing sources users can check

An answer with citations is only useful if the citations are real and point to the right place. How to prompt for them, verify them, and show them.

· 3 min read · Usefully team


When a model answers from web search results, citations turn "trust me" into "check for yourself". But citations can go wrong in quiet ways: a number that points to the wrong source, a source that doesn't say what the sentence claims, or a URL the model made up. This post covers how to get citations that hold up, using Usefully's web search and any chat model.

Give the model something to cite

A model can only cite reliably what's in front of it. Search with POST /v1/search, ask for page text with include_content, and number each source in the prompt with its title, URL and published date. Each result carries title, url, snippet and, when known, published_at.

def format_sources(results):
    return "\n\n".join(
        f"[{i}] {r['title']}\nURL: {r['url']}\nPublished: {r.get('published_at') or 'unknown'}\n"
        f"{(r.get('content') or r['snippet'])[:3000]}"
        for i, r in enumerate(results, 1)
    )

Prompt for citations explicitly

Be specific about format and about what to do when the sources fall short:

Answer using only the numbered sources below.
After each sentence that states a fact, cite the source number in brackets, like [2].
Cite only sources that directly support the sentence.
If the sources don't answer the question, say so instead of guessing.
Never write URLs yourself; use source numbers only.

The last line matters. If the model only ever writes numbers, your code controls every URL the user sees, and a made-up link is impossible.

Verify in code

Before showing an answer, check that every citation refers to a source you actually passed in. It's a few lines and catches the most embarrassing failure:

import re

def check_citations(answer: str, results: list) -> list[int]:
    cited = {int(n) for n in re.findall(r"\[(\d+)\]", answer)}
    invalid = [n for n in cited if not 1 <= n <= len(results)]
    if invalid:
        raise ValueError(f"Answer cites unknown sources: {invalid}")
    return sorted(cited)

For higher-stakes answers, add a second, cheaper check: ask a small model whether each cited source supports the sentence that cites it, and drop or flag sentences that fail. It adds a request per answer, so reserve it for features where accuracy matters most.

Show citations well

  • Turn numbers into links using the URLs from your search results, not from the model's text.
  • Show the source list below the answer with titles and domains, so users can judge credibility at a glance.
  • Show dates when you have them. "Published March 2026" tells a reader whether the answer might be stale.
  • Mark uncited sentences differently, or instruct the model to avoid them, so users know what's grounded.

Choose sources you'd stand behind

Citations make the quality of your sources visible, for better or worse. Use include_domains to search only official documentation or trusted publications when the question allows it, and exclude_domains to keep out sites you don't want quoted. For time-sensitive topics, freshness keeps old pages out.

Cost

Search is billed per query and the answer per token, from the same balance. Trimming each source to a few thousand characters keeps the prompt affordable and, in practice, tends to improve citation accuracy, because the model has less irrelevant text to wander into.

When the sources disagree

Search results sometimes contradict each other, especially on fast-moving topics. Tell the model what to do: prefer the most recent source, prefer official sources over commentary, or present both views with their citations. Leaving it unsaid means the model picks one silently, and the user never learns there was a disagreement. Showing both sides, each with its citation, is usually the most honest option, and it lets the reader decide which source they trust.

See the search guide for every search option, and building a RAG pipeline on live web search for the full pipeline. Try queries on the search page.

More articles

Get started

Your first request is five minutes away.

  • $1 of free credit to start
  • No card, no subscription
  • Keep the SDK you already use
  • Real people at support@usefully.info
Citing sources users can check · Usefully