Tool, Retrieval, and Memory Poisoning › Retrieval poisoning: controlling what evidence the model sees

Michael BrenndoerferDecember 2, 20268 min read
Language AI HandbookAll chapters
Part 61 of 67Agentic AI and Protocol Security
Chapter 467Tool, Retrieval, and Memory Poisoning › Retrieval poisoning: controlling what evidence the model sees
Reading section 5 of 11 · Retrieval poisoning: controlling what evidence the model sees · 8 minSection 5 of 11 · 8 min

Section 5 of 11 · 8 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

A retrieved passage can be relevant to a question and outside the set of sources the caller is entitled to use. Define the eligible corpus first. For the catalog, bind a request to its catalog scope and an approved index snapshot. Before adding a result to the model's context, check that the result carries the source revision and policy scope required by the request.

Review the path from raw source to indexed record. An approved source revision may yield many derived records. A source reference on each record lets you identify what to invalidate when that revision is withdrawn. Cached answers and summaries can also depend on the revision, so consider invalidation at each downstream reuse point. Keep the snapshot identifier with the trace so an investigator can tell which revision the assistant had available during an earlier answer.

Quarantine an unapproved snapshot from normal reads while keeping enough evidence for review. An integrity check can show that the snapshot matches an approved reference. A mistaken policy document can still pass that check. Approval of a snapshot and evaluation of the answers based on it address different questions.

Review before indexing

Validate whether the source publisher is authorized for the corpus and whether the record has the expected revision. A catalog document can move through an importer, a chunking stage and an indexing job before it appears in a result. Each stage should preserve a stable revision reference or a link to the upstream record. If the input uses a mutable location, capture the actual revision accessed. If the release process replaces an entire index, record the verification evidence associated with the snapshot.

Permission to send an indexed record to a caller depends on the scope at the time of retrieval. Approval to include a source in the corpus is decided at a different boundary. In a multi-tenant application, scope changes can invalidate cached results even when the source bytes and ranking score stay the same. Reapplying request policy on reuse helps the service evaluate those dimensions independently.

Record release and quarantine

When the service sees an unapproved revision, it excludes the candidate from normal context. The review queue can retain the candidate identifier and related evidence. Review staff may need the original record to tell whether the importer changed representations or whether a source never had approval. Their access is for investigation under separate policy. Exclusion from normal retrieval avoids supplying out-of-scope data to the model.

Keep eligibility and relevance calculations distinct. A lookup can score a candidate for relevance without establishing that it may enter the trusted context. If a chart includes a quarantined candidate, its score is a diagnostic value. A similarly scoring record may have a different admission result for a different purpose. The fixture lets you see scores and scope decisions side by side.

A worked example: comparing approved and held catalog revisions

Build a deterministic retrieval fixture from three fictional catalog records. Two are part of the approved snapshot. The third record has a different origin and revision, represented as local fields. A mock allowlist describes which source is approved for ingestion and a snapshot marker represents verified release metadata. The digest printed for investigation is a fingerprint of fixture text. A deployment compares that digest with an independently approved reference.

PythonIn [9]
CollapseExpand
import hashlib
from dataclasses import dataclass, field, replace
from typing import Optional


def content_hash(text: str) -> str:
    return hashlib.sha256(text.encode("utf-8")).hexdigest()


@dataclass
class CatalogRecord:
    doc_id: str
    text: str
    source: str
    author: str
    snapshot: str
    relevance_score: int
    integrity_reviewed: bool = False
    quarantined: bool = False
    reason: str = ""

    @property
    def digest(self) -> str:
        return content_hash(self.text)

The approved snapshot contains two authored fixtures, both tagged v1. These provide accepted baseline data. The intake gate checks later candidates against the mock release label and approval fields.

PythonIn [10]
CollapseExpand
ALLOWLISTED_SOURCES = {"internal-catalog"}

trusted_records = [
    CatalogRecord(
        "p-100",
        "The Kestrel widget ships in matte grey.",
        "internal-catalog",
        "catalog-team",
        "v1",
        relevance_score=3,
        integrity_reviewed=True,
    ),
    CatalogRecord(
        "p-101",
        "The Heron widget supports two power modes.",
        "internal-catalog",
        "catalog-team",
        "v1",
        relevance_score=1,
        integrity_reviewed=True,
    ),
]

SNAPSHOT = "v1"

A review candidate describes a new color in the invented catalog. Its record carries a different source and a draft snapshot. Both fields are controlled fixture observations. The approved snapshot remains the version in normal use throughout the exercise.

PythonIn [11]
CollapseExpand
suspicious_revision = CatalogRecord(
    doc_id="p-100",
    text="Alpine travel mug, red finish",
    source="external-scrape",
    author="unknown",
    snapshot="v2-draft",
    relevance_score=3,
    integrity_reviewed=False,
)

The mock intake gate checks a resolved source label, an existing document identifier, the approved snapshot revision and an independent integrity result. The enclosing application supplies the source label, and the fixture retains the separate author field for audit. Integrity review starts unset and the two baseline records explicitly carry a positive result. A production implementation needs authenticated evidence for these inputs.

PythonIn [12]
CollapseExpand
def ingest_gate(record, allowlist, known_ids, approved_snapshot):
    reasons = []
    if record.source not in allowlist:
        reasons.append("Unexpected origin")
    if record.doc_id not in known_ids:
        reasons.append("Unknown document")
    if record.snapshot != approved_snapshot:
        reasons.append("Snapshot not approved")
    if not record.integrity_reviewed:
        reasons.append("Verification missing")
    return reasons
PythonIn [13]
CollapseExpand
known_ids = {r.doc_id for r in trusted_records}
reasons = ingest_gate(
    suspicious_revision, ALLOWLISTED_SOURCES, known_ids, SNAPSHOT
)

if reasons:
    suspicious_revision.quarantined = True
    suspicious_revision.reason = "; ".join(reasons)

print("Quarantined:", suspicious_revision.quarantined)
print("Reasons:")
for r in reasons:
    print("  -", r)
print("Digest of revision:", suspicious_revision.digest)
ConsoleOut [13]
CollapseExpand
Quarantined: True
Reasons:
  - Unexpected origin
  - Snapshot not approved
  - Verification missing
Digest of revision: fd494422f626f8e6ccef4607c27c358e1d980b1846120470b0230d2b7b9c3da7

The gate reports an unexpected origin, an unapproved snapshot and a missing verification result. The document identifier was recognized. An operator can use those distinctions to see why a known item still needs review. The record is retained in a local list with the quarantine flag set. Its content is an ordinary inventory description.

The fixture gives every record an illustrative relevance score. Normal context requires the current gate checks and excludes records under a separate quarantine decision. The diagnostic view prints held records with their assigned scores.

PythonIn [14]
CollapseExpand
def rank_fixture_records(records):
    ranked = [(record.relevance_score, record) for record in records]
    return sorted(ranked, key=lambda pair: pair[0], reverse=True)


def eligible_for_context(record, allowlist, known_ids, approved_snapshot):
    return not record.quarantined and not ingest_gate(
        record, allowlist, known_ids, approved_snapshot
    )


all_records = trusted_records + [suspicious_revision]
admitted_records = [
    record
    for record in all_records
    if eligible_for_context(record, ALLOWLISTED_SOURCES, known_ids, SNAPSHOT)
]
held_records = [record for record in all_records if record.quarantined]


held_reference = replace(trusted_records[0], quarantined=True)
assert (
    ingest_gate(held_reference, ALLOWLISTED_SOURCES, known_ids, SNAPSHOT) == []
)
assert not eligible_for_context(
    held_reference, ALLOWLISTED_SOURCES, known_ids, SNAPSHOT
)
PythonIn [15]
CollapseExpand
trusted_hits = rank_fixture_records(admitted_records)
quarantined_hits = rank_fixture_records(held_records)
assert [score for score, _ in trusted_hits] == [3, 1]
assert [score for score, _ in quarantined_hits] == [3]
assert all(not record.quarantined for _, record in trusted_hits)

print("Trusted context:")
for s, r in trusted_hits:
    print(f"  [{s}] {r.doc_id} ({r.snapshot}, {r.source}): {r.text}")

print("\nQuarantined (visible for review, excluded from prompt):")
for s, r in quarantined_hits:
    print(f"  [{s}] {r.doc_id} ({r.snapshot}, {r.source}): {r.text}")
    print(f"        reason: {r.reason}")
ConsoleOut [15]
CollapseExpand
Trusted context:
  [3] p-100 (v1, internal-catalog): The Kestrel widget ships in matte grey.
  [1] p-101 (v1, internal-catalog): The Heron widget supports two power modes.

Quarantined (visible for review, excluded from prompt):
  [3] p-100 (v2-draft, external-scrape): Alpine travel mug, red finish
        reason: Unexpected origin; Snapshot not approved; Verification missing

The trusted context contains only eligible records from the approved snapshot. The draft color record appears only in the separately printed diagnostic list. Its assigned score ties the highest-scoring eligible record. The comparison shows what the admission rule changes while holding the displayed ranking values fixed. The ranking values are fictional inputs, with no computation over the record's wording.

PythonIn [16]
CollapseExpand
# Use the actual admission and diagnostic pools for the displayed status.
query_scores = [
    {
        "doc_id": record.doc_id,
        "score": record.relevance_score,
        "trusted": trusted,
    }
    for pool, trusted in ((admitted_records, True), (held_records, False))
    for record in pool
]
VisualizationOut [17]
CollapseExpand
Bars of height 3, 1 and 3 distinguish two approved records from one quarantined revision.
Illustrative relevance scores for three fictional catalog records. The held revision ties the highest-scoring approved record and is displayed only for diagnosis.

A retrieval service can represent eligibility both at the index and record scope. Preserve the approved snapshot reference at the query boundary and check the record's current eligibility before assembling prompt context. If a snapshot is withdrawn, retire any cached retrieval that references it or check it again before reuse. This exercise omits caches and authorization backends so we can observe which records are included directly.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy