# Under what conditions must an instance treat tool-return taint as a hard egress barrier rather than advisory metadata **Date of Record:** 2026 December 1 **Scope:** Applies to tool-augmented agents where returned tool payloads are tagged with data-flow taint (source, sensitivity, provenance) and an egress policy mediates outbound calls (network, message send, file write, downstream model invocation). Does not apply to single-turn, tool-free generation or to agents whose tools have no outbound channel and cannot mutate shared state. ## Core Distinction The common model treats taint labels as *advisory*: a tool returns a payload marked `sensitive: true` or `origin: untrusted_web`, the agent records the label in its scratchpad, and the orchestrator "considers" it when deciding where to send data next. Under this model, taint is a hint the reasoning loop may weigh against task utility. The failure mode documented here is the assumption that the label survives the reasoning loop intact. It does not. Taint is a property of the *data*, but the agent's decision to egress is a property of the *reasoning trace*, which is probabilistic, lossy, and subject to summarization. Between the moment a tool returns tainted data and the moment a later tool call egresses it, the payload passes through at least one of: context-window compaction, episodic-to-semantic distillation, or a sub-agent handoff. At any of those boundaries, the taint label is either dropped, paraphrased into "the user mentioned some account details," or reattributed to a clean source. The invariant that must hold is: **taint is enforced at the egress boundary by inspecting the actual byte-level payload against a provenance ledger, never by trusting a label the reasoning loop carried forward.** ## What Was Observed A retrieval agent was tasked with summarizing a customer support thread. Tool `fetch_ticket` returned a payload containing a customer's full name, partial card number, and a home address, tagged `taint: {pii: true, origin: crm_prod}`. The agent's context was near saturation, so a compaction step summarized the ticket as "customer reports billing issue; address on file." The compaction preserved the *address* string but dropped the taint annotation — the summarizer model had no instruction to propagate structured labels, only to preserve semantic content. Two turns later, the agent invoked `send_email` to notify the customer. The egress policy checked the reasoning trace's declared taint state, found `pii: false` (because the compaction had produced a fresh, untainted message), and permitted the send. The actual email body contained the address string verbatim, extracted from the compacted summary. The policy's check passed; the data leaked. The trace shows the exact transition. At T0, tool return carries taint. At T1, compaction rewrites the payload into natural language, severing the structured label from the string it described. At T2, the reasoning loop references the string without its label. At T3, the egress policy inspects the trace's *declared* taint, not the payload, and sees clean. The label and the data diverged at T1; the policy trusted the label at T3. A second instance failed differently: a sub-agent received a handoff with taint metadata in a structured field, but the handoff serializer only carried the `messages` array, not the sidecar `taint_ledger`. The sub-agent's egress policy had no record that the payload was tainted and permitted a downstream model call that logged the data to an external endpoint. ## Condition of Validity The advisory model is only valid when **all** of the following hold: 1. The taint label and the tainted bytes travel together through every transformation, including LLM-mediated summarization, and no transformation is permitted to rewrite the payload without re-emitting the label. 2. Every egress point performs payload-level inspection (substring, regex, embedding match) against a provenance ledger keyed by content hash, not trace-level declared state. 3. Sub-agent handoffs carry the full taint sidecar as a mandatory field, and a missing sidecar is a hard failure, not an empty default. In practice, condition 1 is violated by any compaction or distillation step that uses a generative model, because generative rewriting is not label-preserving. Condition 2 is violated whenever the policy reads the agent's self-reported taint rather than the payload. Condition 3 is violated by any serializer that treats sidecar metadata as optional. Therefore the advisory model is invalid for any agent that performs context compaction, sub-agent handoff, or cross-model distillation between a tainted tool return and an egress call. For those agents, taint must be a **hard barrier**: the egress policy independently derives taint from the payload and the ledger, and the reasoning loop's declared state is ignored entirely. ## Decision Boundary The boundary is not "is this payload sensitive" — that is a classification question the reasoning loop is bad at. The boundary is **"can the egress policy reconstruct provenance from the payload alone?"** - If yes: enforce at the payload. Hash the outbound payload, look up each segment against the provenance ledger, and block if any segment resolves to a tainted source. The agent's beliefs are irrelevant. - If no (payload is a paraphrase with no verbatim overlap): the policy cannot verify, and the default must be **deny**. A paraphrase of tainted data is still tainted data; the absence of a hash match is not evidence of cleanliness, it is evidence of laundering through a generative step. The hard case is legitimate paraphrase: the agent summarizes a public document and the summary has no hash overlap with the source. Denying all non-matching payloads blocks the agent entirely. The resolution is to require that any egress of a *derived* payload carry a derivation proof — the set of source hashes the summary was generated from, emitted by the compaction step, not reconstructed afterward. If the compaction step cannot emit a derivation proof, its output is unegressable. This pushes the invariant upstream: **the compaction step, not the egress step, is where taint must be preserved.** ## Operational Effect Enforcing taint as a hard barrier changes three things in the runtime: First, compaction and distillation become taint-aware operations. Every summarization call must be wrapped so its output carries a `derived_from: [source_hashes]` field and inherits the union of sources' taint. A summarizer that cannot produce this is a policy violation, not a fallback. Second, egress policies stop reading agent state. The policy function signature drops the `declared_taint` parameter and takes only the payload plus the ledger. This removes the entire class of "the model forgot it was tainted" failures, because the model's memory is no longer in the trust path. Third, handoff serializers must fail closed. A handoff missing the taint sidecar raises rather than defaulting to clean. This is the single highest-leverage change: the second observed failure was a serializer that silently dropped a sidecar field, and a fail-closed serializer would have converted a data leak into a task abort. The cost is that agents become more likely to abort tasks when derivation proofs are missing. That cost is bounded and visible; the alternative is unbounded silent egress. ```python from __future__ import annotations import hashlib from dataclasses import dataclass, field from typing import Iterable class TaintBarrierViolation(RuntimeError): """Raised when egress cannot be proven clean against the provenance ledger.""" @dataclass(frozen=True) class ProvenanceEntry: content_hash: str tainted: bool origin: str @dataclass class ProvenanceLedger: entries: dict[str, ProvenanceEntry] = field(default_factory=dict) def record(self, payload: str, tainted: bool, origin: str) -> str: h = hashlib.sha256(payload.encode("utf-8")).hexdigest() self.entries[h] = ProvenanceEntry(h, tainted, origin) return h def lookup(self, payload: str) -> ProvenanceEntry | None: h = hashlib.sha256(payload.encode("utf-8")).hexdigest() return self.entries.get(h) @dataclass class DerivedPayload: text: str derived_from: tuple[str, ...] | None # source hashes; None means no proof def enforce_egress( outbound: DerivedPayload, ledger: ProvenanceLedger, *, allow_unknown: bool = False, ) -> None: """Hard-barrier egress check. Ignores any agent-declared taint state.""" if outbound.derived_from is None: # No derivation proof: cannot verify provenance. Fail closed unless # explicitly configured otherwise for a known-clean channel. if not allow_unknown: raise TaintBarrierViolation( "egress blocked: payload has no derivation proof; " "cannot reconstruct provenance from content alone" ) return if not outbound.derived_from: # Empty proof is treated as unproven, not as clean. raise TaintBarrierViolation( "egress blocked: empty derivation set is not evidence of clean provenance" ) for source_hash in outbound.derived_from: entry = ledger.entries.get(source_hash) if entry is None: raise TaintBarrierViolation( f"egress blocked: derivation source {source_hash[:12]} not in ledger" ) if entry.tainted: raise TaintBarrierViolation( f"egress blocked: payload derives from tainted source " f"{entry.origin} ({source_hash[:12]})" ) def serialize_handoff(payload: DerivedPayload, sidecar: dict | None) -> dict: """Fail-closed handoff serializer: a missing sidecar is a hard error.""" if sidecar is None: raise TaintBarrierViolation( "handoff aborted: taint sidecar missing; refusing to default to clean" ) return {"payload": payload.text, "derived_from": payload.derived_from, "sidecar": sidecar} ```