How answers carry their sources: citation tracing is really a context-budget problem
Start with a common production scene: the answer ends with a row of [1][2][3], each linking to a whole document page, and after three screens of scrolling the user still cannot find the sentence. The logs show two problems — the model also numbered claims that came from its own parametric memory, and one number pointed at a chunk truncated by a token cap, so the quoted sentence never entered the prompt. The second problem is not the model lying; it is you wrote the citation requirement outside the budget.
This article answers one question: how should the chain be designed so an answer with sources does not end up "looks cited, cannot be verified".
Three trust levels — do not mistake numbering for a citation
| Level | Form | Who guarantees it | What you can verify |
|---|---|---|---|
| Lowest | Prompt asks for [1], you maintain the numbering | Nobody | Whether the number is right depends on the model's discipline |
| Middle | File-level annotation (OpenAI Responses API file_citation, annotations carrying index, file_id, filename) | The platform guarantees a real file | You know which file, not which passage |
| Highest | Paragraph-level citation (Anthropic citations, returning cited_text plus 0-indexed start_char_index/end_char_index) | The docs state citations are "guaranteed to contain valid pointers to the provided documents" | You can diff against the source text and check whether the sentence supports the claim |
OpenAI's file_citation carries an easily missed detail: index is a position in the output text, not a position in the source document. And file_search_call does not return search results by default — you need the explicit include parameter to get them back. File-level annotation is therefore enough for "source hints" but not for "claim verification".
Anthropic adds three facts that directly affect budget and implementation: cited_text does not count toward output tokens (nor toward input tokens when passed back), but enabling citations slightly increases input tokens (system prompt additions and chunking); plain text and PDF documents are auto-chunked by sentence, so the minimum citation unit is a sentence; custom content documents get no further chunking and are cited by the block indices you supply. Also, citations and structured outputs are incompatible — enabling both returns a 400. If you need JSON output and citations, you give one up first.
Why citations come first as a budget problem
A citation only holds if the quoted source text sits in the prompt verbatim. That welds citations to the context budget. A worked example:
- Input budget 4,096 tokens; system prompt plus question takes 600 → 3,496 available;
- Chunks average 512 tokens → at most 6 fit (3,072 tokens, 424 left);
- Squeeze in 8 by truncating each to 437 tokens — and what gets cut is usually the concluding sentence at the end of a passage, so the exact sentence
cited_textpoints at is no longer in the prompt.
Two hard rules follow:
- Trim in whole chunks, never by token count. Better to drop one chunk than to cut a chunk in half.
- Reserve budget for citation anchors. If the supporting sentence of chunk 6 sits at its very end, drop an irrelevant chunk 7 rather than compressing every chunk.
Further: the finer the granularity, the tighter the budget requirement. Paragraph-level citations need complete sentences, file-level annotations only need the file present, and prompt-level numbering needs nothing — the price difference between the three levels is essentially how much budget you reserve for verifiable source text.
Three engineering traps that falsify citations
- Renumbering after rerank. If
[1]means "the first item after reordering", while cache, logs and the frontend each hold a different stage's numbering, citations point at the wrong document. Keep only stablechunk_idinternally and generate display numbers at final output time. document_indexaccumulates across messages. Anthropic's docs state document indices are "0-indexed from the list of all document content blocks in the request, spanning across all messages" — in multi-turn conversations, passing history documents back shifts every index. Your local mapping must be recomputed from this request's document list, never carried over from the previous turn.- Chunk granularity does not match citation unit. To cite a single table row or bullet, plain text documents only get you to sentence level; switch to custom content documents and cite by block. Otherwise you get "cited a whole passage, one sentence of which mattered".
Acceptance: two computable metrics
- Citation precision: sample 50 cited answers and check one by one whether
cited_text(or the corresponding source text) actually supports the claim. Below threshold, look at budget truncation and numbering drift before blaming the model. - Citation coverage: the share of factual statements that carry a source. For the rest, label them "no supporting evidence found in the knowledge base" — far more honest than inventing a number.
Both metrics must trace back to a specific chunk and character range; otherwise "citations" are just typography.
Closing
Citations are not about the model "remembering to number things"; they are a verifiable chain: source text enters the prompt (budget) → the platform returns exact locations (granularity) → you render numbers at output (display). Break any link and the user sees only a good-looking square bracket.