Mental model
An AI answer view should preserve who produced each piece of content and how a claim connects to its evidence. Keep assistant prose, quoted user material, tool output, and source references as typed parts instead of flattening them into one string. Distinct labels and accessible visual boundaries help users inspect provenance without implying that a citation automatically proves a claim.
Theory
Streaming interfaces receive different kinds of information at different times. A message may contain text deltas, tool activity, and source parts; a source URL or document reference is not another sentence from the assistant. The AI SDK UI stream protocol represents these as typed parts, including source-url and source-document. The Responses API similarly exposes output messages and annotations such as URL or file citations. Preserve these structures from transport parsing through rendering so a citation remains attached to the response and claim that produced it.
Use a provenance model with at least four categories: assistant-generated claim, user-provided or quoted text, tool result, and external source. The displayed label should describe origin, not confer a trust score. A retrieved page can be irrelevant or stale; a tool result can be incomplete; a model sentence can remain uncited. Source metadata tells the interface where material came from, but it does not establish that the source supports every nearby sentence.
For precise attribution, have the server associate source IDs with the claims they support. If the backend only supplies message-level sources, label them as references for the answer as a whole rather than attaching every source to every sentence. If the API returns character offsets for citations, convert offsets against the exact unmodified text before adding Markdown formatting or truncating it. A transformation that changes character positions can move a citation onto the wrong phrase.
Trade-offs
Visual separation reduces ambiguity but adds density. A source card after every sentence can make a short answer unreadable, while one collapsed source drawer can hide the relationship between a claim and its support. A useful compromise is a compact inline marker for claims with explicit links and a keyboard-accessible source list that reveals title, domain, and the linked claim. Keep quote blocks and tool outputs visually distinct from assistant prose, and retain a textual label when the display is narrow or high-contrast mode is active.
Color can reinforce a distinction, but must not carry it alone. Pair color with labels such as “Assistant answer,” “Quoted text,” “Tool result,” and “Source,” use semantic structure, and maintain sufficient text and focus contrast. Do not make a green source chip mean “verified” unless a defined verification process has actually run. External URLs should be normalized and restricted to safe schemes before rendering; a source title is untrusted content and should be inserted as text, not interpreted as markup.
Failure modes and misconceptions
Flattening a stream into one string can erase the difference between a tool's answer and the assistant's summary. A source list rendered beside a paragraph can also imply stronger attribution than the data provides. If the system knows only that a page was retrieved, show it as a retrieved source; do not imply that it supports a specific claim until the server provides that link or a human verifies it.
Citation offsets are fragile when the UI inserts whitespace, Markdown elements, truncation, or translated text before resolving them. Store citations against stable claim IDs or resolve offsets on the canonical text, then render without changing the indexed span. Missing source metadata should not crash the response: show the claim with an explicit “No linked source” state when appropriate. Likewise, block unsafe javascript: URLs, avoid hidden links that cannot receive keyboard focus, and ensure that a screen reader can identify a source card independently of its background color.
Decision scenario
A research assistant streams a paragraph of generated explanation, two source URLs, and a tool result that includes a short retrieved quote. The backend does not provide claim-level citation mappings. Render the explanation as assistant-written text, render the quote as retrieved material with its source identity, and place the URLs in an “Answer references” list. Do not add an inline citation after every sentence, because that would invent relationships the data did not establish.
If the product needs sentence-level support, change the response contract to carry stable claim IDs and source IDs for each relationship, validate those IDs against the source parts, and test the renderer with missing or reordered events. This keeps the UI honest when stream parts arrive separately. The same rule applies after reconnect: associate each part with its message and request ID before merging it into the visible answer.
Learning outcomes
- Preserve text, source, tool, and quote parts as separate typed data through rendering.
- Explain why displaying a source beside an answer does not prove that it supports every claim.
- Use labels, semantic structure, keyboard access, and contrast together to communicate provenance.
Quantitative model
For a display audit, let be the number of claims explicitly marked as source-backed and the number of those claims with at least one visible, valid source link. When , citation-link coverage is:
If an answer has 23 source-backed claims and 18 visible claim-to-source links, . This checks rendering completeness, not factual correctness; when , report the metric as not applicable rather than 100%.
Implementation pattern
Build the source relationship before rendering. The example keeps each claim's source IDs explicit, validates external URLs, and gives both the claim and its source list a readable label. Production code should also validate IDs against the source records from the same response.
tsxtype Source = { id: string; title: string; url: string };type Claim = { id: string; text: string; sourceIds: string[] };function safeHttpsUrl(raw: string): string | null {try {const url = new URL(raw);return url.protocol === 'https:' ? url.toString() : null;} catch {return null;}}export function AnswerClaims({ claims, sources }: { claims: Claim[]; sources: Source[] }) {const byId = new Map(sources.map(source => [source.id, source]));return <section aria-label="Assistant answer">{claims.map(claim => <article key={claim.id} className="assistant-claim" aria-label="Assistant-generated claim"><p>{claim.text}</p>{claim.sourceIds.length > 0 && <ul aria-label="Linked sources">{claim.sourceIds.map(id => {const source = byId.get(id);const href = source && safeHttpsUrl(source.url);return <li key={id}>{source && href ? <a href={href} target="_blank" rel="noreferrer">Source: {source.title}</a> : <span>Source unavailable</span>}</li>;})}</ul>}</article>)}</section>;}