Sub topic 5
Choosing a citation format
This chapter compares the two main ways to get citations out of a model: inline markers and structured claims. It assumes you can write basic Python, call a model through an API, and read JSON. It also assumes you already number your chunks, as covered in the previous chapter.
The two formats
A citation format is the shape the model uses to say which source backs which statement. Your code must be able to parse it, so the format you choose decides what you can check later.
Inline markers put the source number in the answer text:
The service retries failed requests up to three times [2]. Timeouts default to 30 seconds [1][3].Structured claims return JSON. Each claim lists its source ids and, optionally, a short quote:
{
"answer": "The service retries failed requests up to three times.",
"claims": [
{
"text": "The service retries failed requests up to three times.",
"source_ids": [2],
"quote": "failed requests are retried up to three times"
}
]
}How they differ
| Property | Inline markers | Structured claims |
|---|---|---|
| Readable as is | Yes | No, you must render it |
| Parsing | A regular expression | A JSON parser plus a schema |
| Streaming to the user | Easy | Harder, since JSON is incomplete until it closes |
| Granularity | Whatever the model chooses | One claim per entry |
| Quote checking | Not available | Built in |
| Failure on bad output | Missing or odd markers | Invalid JSON, wrong fields |
Inline markers are simple and keep the answer natural. They do not tell you which part of a sentence a marker covers. A marker at the end of a long sentence may support only one clause.
Structured claims make each statement a unit your code can inspect. You can check every source_ids entry and test every quote against the source text. The cost is more tokens, a stricter prompt, and a parsing step that can fail.
What both formats share
Both formats rely on the same identifiers. Whatever the model writes must map back to a source number you supplied. That mapping is what lets you validate citations later. A format with no stable ids, such as "according to the docs", cannot be checked and should be avoided.
Neither format proves the answer is grounded. A model can attach a valid number to a claim the source does not support. The format only decides what you can test, and later chapters cover those tests.
Decision criteria
Pick inline markers when:
- The answer streams to a chat window.
- You want a low-effort first version.
- Checking that numbers are in range is enough for now.
Pick structured claims when:
- You must audit each statement, for example in legal, medical, or support workflows.
- You want to verify quotes against source text.
- A human reviewer will inspect the claim list.
You can also combine them. Ask for structured output, then render the answer text with inline links for the user. The claim list stays available for checks and logs.
Common errors
- Mixing numbering schemes. If the prompt numbers sources from 1 but the format example shows
[0], the model will copy the example. Keep them consistent. - Asking for both without saying which wins. If the model writes markers inside structured claims, parsing becomes ambiguous. Specify one location for citations.
- Trusting JSON mode to enforce meaning. A schema guarantees shape, not truth. A
source_idsvalue of[9]is valid JSON even when only four sources exist.
Exercise
Your support bot streams answers to users, and a compliance team wants to check that every quoted phrase really appears in the cited document. Which format would you choose, and how could you keep streaming?
Show answer
Use structured claims, because only they carry a quote field that code can test against the source text. To keep streaming, either stream the answer text separately from the claim list, or generate the answer first and then run a second step that extracts claims with quotes for the compliance check. The user sees text quickly, and the claim list is checked afterward.