D4 · Prompt Engineering › Cluster 8 · Reliability, Hallucination & Iteration

8.2 · Grounding in Documents & Citations

Answer only from the source

CONCEPT Provide the source, then constrain the answer to it

Grounding means the answer is derived from documents you supply rather than the model's training data. It's the structural cousin of 8.1: where 8.1 lowers the pressure to answer, grounding gives Claude the material and then restricts it to that material. Three moves compose it:

The verification loop is the powerful bit: "After drafting, review each claim. For each, find a direct supporting quote in the documents. If you can't, remove the claim and mark it with empty [] brackets." Claude polices its own output against the source.

CONCEPT The Citations capability (high level)

Beyond prompting Claude to quote passages, the Claude API has a built-in Citations feature that grounds answers structurally rather than by instruction. You set citations: {enabled: true} on each document content block; the response then splits into multiple text blocks, and cited blocks carry a citations array. Each citation gives you the cited_text, the document_index, the document_title, and a location — char_location for plain text or page_location (1-indexed pages) for PDFs.

🔑 Key facts for the exam: Citations needs no beta header; it must be enabled on all documents or none; and it is incompatible with structured outputs (output_config.format) — combining them returns a 400. The model produces verifiable references to exact source spans instead of you parsing quotes out of prose.

DIAGRAM Prompted quoting vs. the Citations feature

flowchart TD D["Source documents
in the request"] --> C{"How to ground?"} C -->|"prompt technique"| PQ["Ask Claude to quote
+ cite each claim in prose"] C -->|"API feature"| CF["citations: enabled
on every document block"] PQ --> V["Verify each claim
against a quote; retract if none"] CF --> R["🟢 Response splits into text blocks;
cited blocks carry cited_text +
document_index + location"] V --> A["🟢 Auditable, source-backed answer"] classDef ok fill:#d4edda,stroke:#28a745,color:#155724; classDef gate fill:#ffe8cc,stroke:#ff9f40,color:#9a4a0a; class A ok; class R ok; class V gate;

CODE Grounding prompt + the Citations request shape

First, the pure-prompt grounding pattern with a self-verification pass:

# Prompt-only grounding: quote, cite, and self-verify
Draft a press release for AcmeSecurity Pro using ONLY information from these briefs.
<documents>{{DOCUMENTS}}</documents>

After drafting, review each claim in the release. For each claim, find a direct
quote from the documents that supports it. If you cannot find a supporting quote,
remove that claim and mark where it was with empty [] brackets.

And the API-native Citations feature — grounding enforced by the platform, not by instructions:

import anthropic
client = anthropic.Anthropic()

resp = client.messages.create(
    model="claude-opus-4-8", max_tokens=1024,
    messages=[{"role": "user", "content": [
        {"type": "document",
         "source": {"type": "text", "media_type": "text/plain",
                    "data": policy_text},
         "title": "Privacy Policy",
         "citations": {"enabled": True}},        # all docs or none
        {"type": "text", "text": "Which sections cover data retention?"},
    ]}],
)

for block in resp.content:
    if block.type == "text":
        print(block.text)
        for c in (block.citations or []):
            print("  ↳ cited:", c.cited_text, "@", c.document_title)

TRADE-OFFS Prompted quoting vs. the Citations feature

Prompt Claude to quoteCitations feature
SetupJust prompt wordingcitations: {enabled: true} per document
EnforcementInstruction — model may driftStructural — returns exact spans + offsets
Output shapeFree prose with inline quotesText blocks with a citations array
LimitsNone, but weaker guaranteeAll-or-none; incompatible with output_config.format
Use the Citations feature when you need machine-verifiable, click-through-to-source references; use pure prompting when you just want the answer anchored and can't (or don't need to) restructure the response.

EXAM TRAPS

Trap: Enabling citations on some documents but not others in one request. → It's all documents or none — a mixed request is rejected.
Trap: Combining Citations with structured outputs (output_config.format). → Incompatible — returns a 400. Pick one: cited spans or a JSON schema, not both in the same call.
Trap: Thinking "grounding" just means pasting the document in. → Providing the source is necessary but not sufficient; you must also restrict Claude to it and ideally verify claims against quotes, or it will still blend in parametric knowledge.
Trap: Assuming Citations requires a beta header. → It does not — it's GA.

PRACTICE

Q1 · A RAG answer looks right but you can't tell which retrieved chunk each sentence came from. Which capability fixes this and how?

Enable the Citations feature (citations: {enabled: true}) on each document block. The response splits into text blocks where cited blocks carry a citations array with cited_text, document_index/title, and a char- or page-location — so every sentence traces to an exact source span.

Q2 · You need both citations and a strict JSON schema in one call. What happens?

You can't — Citations is incompatible with output_config.format and the request returns a 400. Split it into two steps (cite first, then structure) or choose the one the task needs most.

Q3 · Without the Citations feature, how do you make a drafted document self-verify against its sources?

Add a verification pass to the prompt: after drafting, have Claude find a direct supporting quote for each claim and remove any claim it can't support (e.g. marking the gap with empty [] brackets). This grounds and audits the output using prompting alone.