Tool, Retrieval, and Memory Poisoning › A shared integrity harness: provenance, validation, and quarantine
Language AI HandbookAll chapters Tool, retrieval and memory decisions need their own controls. They can share an evidence format: the incoming object, the check results, and the decision for a stated use. The next fixture exercises this record using three inputs.
Provenance as a first-class field
For each record the application uses to support a decision, retain the provenance fields relevant to that use. The catalog needs the publisher identity and revision. When comparing artifact contents, retain the verification result and independent reference used for the comparison. Establish freshness with its own policy.
Trust in the provenance metadata depends on its issuance. Record the identity of the authority that assigned each field. In production, a digest needs an independent expected value and a provenance record needs a verified issuer or trusted capture path. The W3C provenance model describes relevant relationships. An application's policy determines how they affect admission or access.
Validation versus authorization versus effect
Use separate decision records for validation, authorization, and observed effect.
- Validation checks the configured structural rules.
- Authorization checks whether the identified principal may use the requested operation or record.
- Effect checking compares the observed outcome with the intended effect, such as whether a stored preference appears in the authorized active read.
The tool example separated validation from permission. In the memory example an approved write can be checked by reading the active entry. At a real effect boundary, the audit record should indicate who observed the change and which request authorized it.
Integrity compares the received artifact to an independently trusted reference. Provenance describes origin and production. Permission describes what the acting principal is entitled to do. Review records who approved a transition and on what evidence. Observed effect is an independent observation of the state the action intended to change. One input can pass an integrity check and still need independent approval before activation.
The harness in code
Use a fixture artifact with a fingerprint, an origin, and a separate review flag. The function evaluates those three inputs before marking the record eligible for promotion. A production effect check would need its own direct observation of what changed.
PythonIn [25]Expand
@dataclass
class Artifact:
content_label: str
source: str
author: str
digest: str
expected_digest: str
trusted: bool = False
def integrity_ok(self) -> bool:
return (
self.digest == self.expected_digest
and self.digest == content_hash(self.content_label)
)
def promote(artifact, allowlist, reviewer_approved: bool):
checks = {
"integrity": artifact.integrity_ok(),
"source_allowlisted": artifact.source in allowlist,
"reviewer_approved": reviewer_approved,
}
artifact.trusted = all(checks.values())
return checksTest one intact approved artifact, one artifact with an inconsistent fingerprint, and one artifact delivered with an unexpected origin and no approval. The cases use neutral labels and are evaluated in memory. Comparing the fingerprint demonstrates the form of the integrity decision. The other flags represent expected origin and independent review. The application may consider artifacts for the next stage only if those prerequisites pass.
PythonIn [26]Expand
publisher = next(iter(ALLOWLISTED_SOURCES))
good = Artifact(
"catalog-entry-a",
publisher,
"catalog-maintainer",
content_hash("catalog-entry-a"),
content_hash("catalog-entry-a"),
)
different_revision = Artifact(
"catalog-entry-b",
publisher,
"catalog-maintainer",
content_hash("catalog-entry-b"),
content_hash("catalog-entry-a"),
)
untrusted = Artifact(
"catalog-entry-c",
"other-catalog",
"unverified-origin",
content_hash("catalog-entry-c"),
content_hash("catalog-entry-c"),
)
for name, art, approved in [
("Approved", good, True),
("Different revision", different_revision, True),
("Other source", untrusted, False),
]:
checks = promote(art, ALLOWLISTED_SOURCES, approved)
print(name, "->", checks, "| trusted:", art.trusted)ConsoleOut [26]Expand
Approved -> {'integrity': True, 'source_allowlisted': True, 'reviewer_approved': True} | trusted: True
Different revision -> {'integrity': False, 'source_allowlisted': True, 'reviewer_approved': True} | trusted: False
Other source -> {'integrity': True, 'source_allowlisted': False, 'reviewer_approved': False} | trusted: FalseThe second candidate fails the integrity comparison because the observed digest differs from the expected value. The third candidate matches its fingerprint but fails both the origin and review comparisons. A matching digest answers neither of the other two checks.
The per-check results can be shown as a matrix, which makes the "all checks must pass" rule visible and shows which gate blocked each artifact.
PythonIn [27]Expand
# Recompute promotion checks for each artifact, keeping per-check outcomes.
harness_artifacts = [
("Approved", good, True),
("Different revision", different_revision, True),
("Other source", untrusted, False),
]
harness_rows = []
for name, art, approved in harness_artifacts:
checks = promote(art, ALLOWLISTED_SOURCES, approved)
harness_rows.append({"name": name, "checks": checks})
gate_names = ["integrity", "source_allowlisted", "reviewer_approved"]
grid = [
[1.0 if row["checks"][g] else 0.0 for g in gate_names]
for row in harness_rows
]VisualizationOut [28]Expand

Each fixture retains its three check results. Promotion requires all three to pass. In a deployment, review evidence should identify the approving party, the artifact and the intended use.
Withdraw a snapshot across read surfaces
When a source revision is withdrawn, compare its identifier with the source references still available to the application. A system can keep a historic copy for audit while making the same copy unavailable to ordinary reads. Treat withdrawal as a state change in the active-read policy. Deleting whatever the index last emitted would make it more difficult to explain how an earlier answer was formed. Leaving it eligible would make a later answer depend on a record the owner has withdrawn.
For this example, a downstream record identifies the set of source revisions that produced it. A plain audit reference points to a reviewed source and never enters ordinary prompt context. An indexed passage and a cached answer both depend on the first catalog revision, and a saved summary depends on it indirectly. The summary already carries a closed set of revision references. The fixture therefore checks set membership without trying to reconstruct a derivation graph. A deployment needs to decide whether to record direct source references, retain the derivation graph, or do both. Either design should let a reviewer locate the records that are eligible to be reused for a given request.
PythonIn [29]Expand
from dataclasses import dataclass
@dataclass(frozen=True)
class ReadRecord:
identity: str
revisions: frozenset[str]
auditing_only: bool = False
records = {
"passage": ReadRecord("passage", frozenset({"catalog-r1"})),
"cached answer": ReadRecord(
"cached answer", frozenset({"catalog-r1", "catalog-r2"})
),
"saved summary": ReadRecord("saved summary", frozenset({"catalog-r1"})),
"other item": ReadRecord("other item", frozenset({"catalog-r2"})),
"audit history": ReadRecord(
"audit history", frozenset({"catalog-r1"}), auditing_only=True
),
}
def available_for_context(record, withdrawn):
return not record.auditing_only and not record.revisions.intersection(
withdrawn
)
before = [
name
for name, record in records.items()
if available_for_context(record, set())
]
after = [
name
for name, record in records.items()
if available_for_context(record, {"catalog-r1"})
]
inactive = [name for name in before if name not in after]
assert after == ["other item"]
assert inactive == ["passage", "cached answer", "saved summary"]
print("Unavailable after source withdrawal:", inactive)
print("Eligible from the remaining revision:", after)ConsoleOut [29]Expand
Unavailable after source withdrawal: ['passage', 'cached answer', 'saved summary'] Eligible from the remaining revision: ['other item']
The withdrawal removes three previously eligible records from normal context. The three remain in the dictionary with their original revision sets. The audit record was already unavailable in normal reads, so it is absent from the newly ineligible list. For the cached answer, retaining both source references matters: if even one contributing revision is withdrawn, you may need to regenerate the answer under the revised policy. Simply attaching the surviving revision would misrepresent the result's origin.
When applying this rule to an application, store the revision expectation alongside the access policy that allowed the original use. The simulated eligibility question is about the withdrawn revision set and the record's purpose flag. Other production decisions also check current principal, scope and authorization. A verified source identity can persist while one particular revision becomes ineligible. A request can retain access to other records from that publisher after the withdrawn revision is excluded. Record the disposition for each affected reuse channel, particularly when caches have their own lifecycle.
This is also a test of the recovery procedure. A restored index snapshot can have the same bytes the service once approved, while the current withdrawal rules still make records inside it ineligible for the present use. Restore historical evidence under an investigation policy and reconstruct ordinary read eligibility from current approved state. Associate the recovery decision with the exact snapshot or revision so a later review can tell which path produced each restored record.
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!