Recipe
LLM grounding + citation design
A repeatable pattern for surfacing provenance in generated text without breaking the reading flow. Inline anchors, hover previews, and a collapsible source index.
Problem
Users trust answers more when they can verify origin. Raw LLM output lacks a native citation layer. Injecting bracketed numbers clutters prose. The challenge is making provenance discoverable without punishing skimmers.
Pattern
- Anchor tokens — wrap claim boundaries in superscript pill markers [1]
- Hover card — on hover, show source title, excerpt, and retrieval score in a floating panel. Dismiss on mouse leave.
- Source index — collapsible footer listing every cited document with a relevance bar and clickable link.
- Highlight sync — clicking a pill scrolls to the index entry and pulses its background for 1.2s.
States
Loading
Skeleton pills pulse while grounding model resolves chunks.
Empty
No retrievable sources. Show inline disclaimer, hide index.
Partial
Some claims grounded, others flagged with low-confidence styling.
Error
Grounding service down. Fallback to raw output with warning banner.
Data contract
{
"text": "The model was trained on...",
"spans": [
{
"start": 24,
"end": 41,
"source_id": "arxiv-2307.09288",
"score": 0.94
}
],
"sources": [
{
"id": "arxiv-2307.09288",
"title": "Llama 2 Technical Report",
"url": "https://arxiv.org/abs/2307.09288",
"excerpt": "We introduce Llama 2..."
}
]
}