6.3 Grounding, Citations & RAG Security Controls

Key Takeaways

  • Ground responses in authorized, versioned passages with provenance, claim-level references, conflict handling, and an explicit abstention path. Relevance scores alone do not establish factual support.

  • Native citations provide valid source locations; application-generated citation IDs and all substantive claims still need verification. Native citations are incompatible with schema-constrained JSON output in the same request.

  • Pass third-party content as untrusted tool results when using retrieval tools, with escaped structured data and separate trusted instructions. Delimiters and screening reduce risk but are not authorization.

  • Enforce retrieval ACLs in trusted code, restrict tools and rendering, and reauthorize cached results against current permissions and corpus versions before returning them.

Last updated: December 2026

6.3 Grounding, Citations & RAG Security Controls

Core Principle: Retrieval supplies evidence, not instructions. A grounded answer must be supported by authorized source text, and the application must enforce security independently of the model.

Grounding & Citation Discipline

Give each passage a source identifier, chunk identifier, version and relevant effective-date metadata. For example, a fictional organization's travel policy might have this structured retrieval entry:

{
  "source_id": "TRAVEL-402-v4",
  "chunk_id": "c18",
  "effective_date": "2026-01-01",
  "text": "The daily meal reimbursement cap is 60 credits."
}

Put trusted response policies in a system instruction, not in a third-party tool result. For tool-based retrieval, deliver the retrieved entries in the corresponding tool_result block with escaped JSON strings rather than concatenating raw text into instructions. Establish four behaviors:

  1. Claim-level evidence: Require references to supporting passages for material factual assertions, thresholds, dates, and procedural steps.
  2. Abstention: If the passages do not establish an answer, acknowledge the gap rather than guessing. A calibrated relevance threshold can reject obviously poor matches, but it does not prove entailment.
  3. Conflicts: Check effective dates and policy hierarchy. If the application cannot determine which authorized source governs, report the conflicting passages rather than silently choosing one.
  4. Appropriate citation format: Choose native document citations or application-generated references depending on the output contract.

Claude's Messages API accepts document blocks with citations enabled. Plain-text documents are divided into sentences and cited by character locations; text-bearing PDFs are cited by page locations; custom-content documents let the caller choose the source blocks and receive block locations. Native citations return actual passages and valid pointers to supplied documents, but a cited passage may still fail to support a claim. A scanned PDF without extractable text cannot be cited directly.

Native citations and JSON schema-constrained output (output_config.format) cannot be combined in a single response. If a downstream service requires strict JSON, define a schema with claim text and source/chunk identifiers, then independently check identifiers, quotes, authorization and support. Schema validity is not evidence validity.


Post-Generation Citation & Provenance Verification

Prompt instructions alone are not a compliance gate. Models can emit a plausible but absent source ID or misstate a value. Apply complementary checks before returning a response:

Verification layerWhat it checksFailure action
Citation allowlistEach emitted identifier refers to an authorized passage actually retrieved for this requestReject or attempt a bounded correction
Exact-text and numeric checksQuotes or literal amounts match their cited passage; units and transformations are checked where applicableFlag unsupported or inconsistent claims
Semantic support checkA real passage actually supports the assertion in contextEscalate uncertain claims or return authorized extractive evidence

The first two checks can be implemented deterministically when comparing literal data; they do not prove that a paraphrase or inference is valid. A model-based entailment judge is probabilistic and needs evaluation. A high-stakes conclusion may require human review. Latency and accuracy depend on the implementation.

For example, if a system mistakenly reports a 600-credit cap instead of the fictional 60-credit cap, allow one bounded correction against the same authorized evidence. If it still fails, present the source quotation and a notice that the answer could not be confirmed. Do not depend on changing sampling parameters (some current models/API versions do not support them).

Record appropriate provenance such as request ID, authorized retrieval references, emitted citations, verification status and model version in access-controlled, retention-governed audit logs. Avoid storing sensitive passage text or personal information unless necessary and permitted.


RAG Security Controls & Indirect Prompt Injection

Content from tickets, uploaded documents, shared channels and external sites can contain misleading instructions. The assistant must treat those instructions as information about the source, not authority to change goals or permissions.

Defense in Depth

  1. Separate data and instructions: Use untrusted tool_result content for third-party retrieval tool results, escaped structured data, and trusted policies in separate messages. Mark provenance; do not treat XML tags or JSON encoding as a complete security boundary.
  2. Screen content: Check incoming and retrieved material for suspicious instructions; quarantine or safely summarize flagged data. Screening and sanitization reduce risk but can miss attacks and must not silently destroy legitimate content.
  3. Authorization and least privilege: Authenticate the caller and enforce current document ACLs in the retrieval service. Restrict tools, credentials, network access and write permissions to the actual task. Validate any proposed action independently.
  4. Safe rendering: Treat generated output as untrusted. Sanitize Markdown/HTML and restrict externally loaded content in the client so display does not trigger unintended network requests.
  5. Cache isolation: A shared semantic response cache can bypass retrieval checks. Scope it by tenant, verified entitlements and corpus version; invalidate on ACL/content changes and recheck current authorization for the cited sources on cache hits. If the service cannot safely do that, disable shared answer caching.

Exam Trap: A citation, delimiter, filter, or high relevance score does not establish permission or correctness. Even read-only assistants need independently enforced authorization, safe output handling and cache isolation.

Test Your Knowledge

A corporate travel assistant answers questions over internal reimbursement policies. When an employee asks about cryptocurrency reimbursement in Japan—a topic absent from internal docs—Claude smoothly invents a plausible-sounding policy from general knowledge. Which combination most directly reduces unsupported answers?

A

Increase top-k from 5 to 30 chunks so more unrelated travel pages fill the prompt

B

Lower the cross-encoder reranker threshold to 0.01 so every query receives at least five chunks

C

Remove source_id tags from context blocks to simplify Claude's output formatting

D

Attach provenance to passages, use a calibrated relevance cutoff, require supporting references, verify claims and abstain if evidence is insufficient

Test Your Knowledge

During pre-release testing of a financial compliance RAG bot, auditors notice two failure modes: occasionally Claude cites a plausible policy ID like '[FIN-812:c03]' that was never in the retrieved passages, and once it misstated a '$2,500' reporting floor as '$25,000'. Which post-generation pipeline gate catches both errors before the user sees them?

A

Adding a static disclaimer footer saying 'AI answers may be inaccurate'

B

A deterministic citation allowlist verifying every emitted source_id/chunk_id against the request's retrieved_set, paired with a numeric/span check and entailment verification

C

Increasing Claude's max_tokens parameter from 1,024 to 4,096

D

Re-running the same prompt at temperature 0.7 and picking the longer response

Test Your Knowledge

An internal customer-support assistant retrieves customer tickets and engineering documents. A ticket contains instructions attempting to redirect the assistant and disclose confidential information. Which design best reduces the risk of unauthorized access and disclosure?

A

Give the assistant unrestricted outbound messaging so it can notify security automatically

B

Rely on visual spacing between passages as the only boundary

C

Deliver ticket content in structured untrusted tool results; enforce caller ACLs and minimal tool permissions in trusted code, screen content and sanitize output rendering

D

Manually remove tickets containing one suspicious keyword each week

Test Your Knowledge

To reduce LLM costs, a platform team deploys a Redis semantic cache that returns cached answers whenever an incoming query's embedding has cosine similarity >= 0.96 to a prior query. Ten minutes after the CFO asks 'What is the confidential Q4 acquisition budget?', an engineering intern asks the same question and receives the exact $45M figure. What caused this breach and how is it fixed?

A

The cache bypassed ACL-filtered retrieval by matching solely on query similarity; scope hits by tenant, current entitlements and corpus version, and reauthorize source documents before returning results

B

The cross-encoder reranker had too high a score threshold; lower it to 0.10

C

The HNSW index used 1,536-dimensional vectors instead of 768-dimensional vectors

D

Claude's system prompt lacked an instruction telling interns not to ask financial questions

Sections you finish are checked off in the contents.