Home / Blog / Dev notes

How to add sources to AI answers, the start of a trustworthy AI feature

Dev notesSOL LABS AI3 min read

Once you add an AI feature to a service, there's one question you hear more than any other: "Where did this answer come from?" Even when the answer is right, if users can't check the evidence right away, they end up looking up the original themselves. That takes away much of the point of having the AI feature.

So if your AI feature answers by reading documents or materials, it's best to start by designing how sources appear next to the answer. Rather than "which documents should we feed in," this post focuses on what comes after: how to show sources on screen.

Showing sources breaks down into three steps

An answer with sources is usually built in this order.

  1. Number the materials: Give every document or passage you pass to the model a number or name.
  2. Attach citations to the answer: The model returns, for each sentence, which part of which material it relied on.
  3. Show the original on screen: When the user clicks a number, the original passage expands or they jump to that page.

Model APIs help a lot with steps 1 and 2. Step 3 is the part you build yourself in your service's UI.

How APIs return citations

Anthropic (Claude) citations. If you turn on the citations option when passing in documents, the answer comes back split into several pieces, each with source information attached. According to the official documentation, plain text and PDFs are chunked into sentences for citation, and the source is given as character positions (text), page numbers (PDF), or block indexes (content you chunked yourself). The original cited sentence (cited_text) comes back too, and the documentation notes that it isn't counted toward output tokens.

OpenAI file search. When you use the file search tool, which answers by searching files you've uploaded, the answer message comes with file citation annotations (file_citation). These contain the file ID, file name, and position information. The retrieved search results themselves aren't returned by default — you have to explicitly ask for them to be included in the request.

ItemAnthropic citationsOpenAI file search
How to enableTurn on citations per documentUse the file search tool
Source unitSentence · page · blockFile + position
Getting the original textCited sentence includedMust request results separately

Either way, the key point is the same: the model returns "this sentence came from this material" as structured data. That's far easier to wire into a UI than asking in the prompt to "please list your sources."

Want to check this against your own data?AI Readiness Assessment · we review your material and map candidates and orderContact us

Patterns for showing sources on screen

When you carry the citation data the API returns over to the screen, three things cover it.

  • Numbers at the end of sentences: Add small numbers like [1] [2] at the end of answer sentences. Leave sentences with no source unnumbered so users can tell the difference.
  • Source preview: Clicking a number expands the cited passage right there. That's quicker to check than jumping to the whole document.
  • Open the original: Put a link to the original file or page below the preview. For documents the user doesn't have access to, show only the title.
Showing sources doesn't stop AI from being wrong — it helps people notice quickly when it is.

What to check before you ship it

  • How does it look on screen when sentences without a source are mixed in?
  • What happens if a document the user can't see gets cited?
  • Does the original appear within a second of clicking a citation number?
  • When the original changes, what happens to citations in earlier answers?

The second one matters most. If your service mixes documents with different permissions, only pass the model materials the user is allowed to see, starting at the step where you hand them over.

Summary

Adding sources to AI answers comes down to three steps: number the materials, get citations back with the answer, and show the original on screen. APIs such as Anthropic's citations feature and OpenAI's file search handle the first two in structured form, so on the service side you can put your effort into the numbers, previews, and open-original UI.

References

  • Anthropic, Citations: https://platform.claude.com/docs/en/build-with-claude/citations
  • OpenAI, File search: https://developers.openai.com/api/docs/guides/tools-file-search
Want to build something similar?

We review your current system and data, then outline the migration order and scope.

Talk to usStart with the 3-minute AI readiness check →
SOL LABS AI

We build web apps, mobile apps and business systems, then add and run the AI they need. We build and operate our own meeting notes, contract and company analysis AI.

See our projects
Get the next post by email?

Related posts