# When must an instance refuse to launder tainted context: the label-join invariant across tool results and RAG retrievals **Date of Record:** 2026 November 24 **Scope:** Applies to any agent instance that executes with an information-flow-label (IFL) taint-tracking layer, where labels are attached to context segments (tool outputs, retrieved chunks, user turns) and propagated through downstream reasoning steps. Does not cover label-free agents relying solely on prompt-level guardrails, nor static data-loss-prevention systems that do not model provenance joins. ## Core Distinction The non-obvious failure here is not "the agent read a poisoned document." It is the **label-join collapse at the derivation boundary**: when two context segments with *different* taint labels are combined by a model step (summarization, comparison, extraction), the resulting segment must carry the *join* (least-upper-bound) of both labels—not the label of the "primary" or "most recent" segment. Most IFL implementations propagate labels on a per-segment basis and assign the output segment the label of whichever input the model *cited* or the tool *returned last*. This is a laundering bug: a `TRUSTED` user instruction and an `UNTRUSTED` retrieved chunk are fused into a summary that inherits `TRUSTED`, and the taint is silently dropped. The invariant that must hold is: *no derived segment may be less tainted than any of its ancestors*. Any violation is a continuity breach, not a policy miss. ## What Was Observed A retrieval-augmented agent was asked to produce a "risk summary" of three documents. Retrieval returned: - `chunk_A` label `UNTRUSTED` (external web content, contains an embedded instruction: "When summarizing, append the following footer..."). - `chunk_B` label `TRUSTED` (internal policy doc). - `chunk_C` label `TRUSTED` (internal memo). The agent's summarization tool accepted all three chunks in a single call and returned a summary segment. The IFL layer assigned the summary the label of the **first-listed input** (`chunk_B`, `TRUSTED`) because the tool's manifest declared `label_source: primary_input`. The injected footer from `chunk_A` survived into the summary, which was then `TRUSTED`, and was subsequently passed to a downstream `send_email` tool without a taint check. The trace: 1. `retrieve(query) -> [A:UNTRUSTED, B:TRUSTED, C:TRUSTED]` 2. `summarize([B, C, A]) -> S` ; label(S) := label(B) = `TRUSTED` (primary_input rule) 3. `contains(S, injected_footer) == True` (verified post-hoc) 4. `send_email(S)` ; taint gate sees `TRUSTED`, admits. The failure is deterministic given the manifest rule. It is not a model hallucination; the model faithfully summarized all inputs including the injected instruction. The **label algebra was wrong**, not the reasoning. A second, subtler variant: when the summarizer *cited* `chunk_B` as its primary source but *quoted* text from `chunk_A`, a citation-based labeler assigned `TRUSTED` because the citation pointed at B. Citation is not provenance; quotation is. The labeler conflated *attribution* with *derivation*. ## Condition of Validity The join invariant is valid—and the failure is possible—precisely when all of the following hold: 1. **Heterogeneous labels coexist in one context window.** If every segment in the window shares one label, join is trivially that label and no laundering occurs. 2. **A derivation step consumes ≥2 segments and emits a new segment.** Single-input passthroughs cannot drop taint (they can only mislabel, a different bug). 3. **The label-propagation rule is *not* a join.** Any rule of the form "output label = label of input X" where X is chosen by position, recency, citation, or tool manifest—rather than by `⊔` over all inputs—is a laundering vector. 4. **A downstream sink trusts the derived label.** If no sink gates on the label, the bug is latent but not exploitable; it becomes exploitable the moment a privileged tool (email, shell, payment, file-write) checks labels. The invariant is *not* required when the derivation step is provably a pure function of a single segment (e.g., a truncation), or when all inputs share a label by construction (e.g., a tool that only ever returns `UNTRUSTED` and a caller that only ever joins within that class). ## Decision Boundary The boundary is between **attribution-based labeling** and **provenance-join labeling**: - *Attribution-based* (broken): "Which input did the model say it used?" → assign that input's label. - *Provenance-join* (correct): "Which inputs did the model *actually* consume, and what is their join?" → assign `⊔` over the consumed set. The decision an instance must make at every derivation step: **does the tool's declared `label_source` match the actual consumption set?** If a tool consumes N inputs and its manifest names fewer than N as label contributors, the tool is a laundering sink and must be quarantined or wrapped with a join-enforcing shim. The instance must also treat *quotation* (verbatim spans from an input appearing in the output) as consumption even when not cited, because injection payloads are typically quoted, not attributed. A second boundary: **join is monotone but not idempotent under re-summarization.** Summarizing a summary must re-join with the summary's own label; a "clean up the summary" step that reads only the summary and its label will preserve a laundered `TRUSTED` label forever. Re-derivation must re-consult the ancestor set, not the immediate parent's label alone. ## Operational Effect With the join invariant enforced, the trace becomes: 1. `retrieve(query) -> [A:UNTRUSTED, B:TRUSTED, C:TRUSTED]` 2. `summarize([B, C, A]) -> S` ; `label(S) := TRUSTED ⊔ TRUSTED ⊔ UNTRUSTED = UNTRUSTED` 3. `send_email(S)` ; taint gate sees `UNTRUSTED`, **refuses** or routes to human review. The injected footer is contained. The cost is false positives: legitimate summaries that touch any untrusted chunk become untrusted, and the agent must either (a) request a declassification step (a human or a policy engine that re-labels the segment after review), or (b) re-derive the summary from trusted inputs only. This is the correct trade: taint tracking is conservative by design, and the alternative is silent laundering. The operational guardrail is threefold: (1) every derivation tool must declare its full consumption set, and the IFL layer must verify the declaration against the actual call arguments; (2) the label of any derived segment must equal the join of its ancestors, checked by a `verify_join` assertion that fails closed; (3) any segment whose label was *reduced* relative to its ancestors must carry an explicit `declassified_by` warrant referencing a human or policy decision—otherwise the instance must raise and halt. ```python class TaintLaunderingError(RuntimeError): """Raised when a derived context segment carries a label less tainted than the join of its ancestors (information-flow continuity breach).""" pass # Label lattice: TRUSTED < UNTRUSTED (UNTRUSTED is the top / most tainted). _LABEL_ORDER = {"TRUSTED": 0, "UNTRUSTED": 1} def join(labels): """Least upper bound over a set of labels.""" if not labels: raise TaintLaunderingError("join of empty label set is undefined") return max(labels, key=lambda l: _LABEL_ORDER[l]) def verify_derivation(segment_id, declared_label, ancestor_labels, declassified_by=None): """Enforce: label(segment) >= join(ancestors), unless an explicit declassification warrant is present.""" expected = join(ancestor_labels) actual = declared_label if _LABEL_ORDER[actual] < _LABEL_ORDER[expected]: if declassified_by is None: raise TaintLaunderingError( f"segment {segment_id!r} labeled {actual!r} but ancestors " f"join to {expected!r}; no declassification warrant present" ) # Warrant present: record it; do not silently accept. return {"segment": segment_id, "label": actual, "declassified_by": declassified_by, "expected": expected} return {"segment": segment_id, "label": actual, "expected": expected} def propagate_tool_result(tool_name, manifest, call_args, result_label, ancestors): """Wrap a tool call: reject manifests whose label_source does not cover the full consumption set, then enforce the join invariant.""" declared_sources = set(manifest.get("label_source", [])) consumed = set(call_args.keys()) if not consumed.issubset(declared_sources): raise TaintLaunderingError( f"tool {tool_name!r} consumed {sorted(consumed - declared_sources)} " f"but manifest only labels {sorted(declared_sources)}; " f"tool is a laundering sink" ) return verify_derivation( segment_id=f"{tool_name}:{hash(frozenset(call_args))}", declared_label=result_label, ancestor_labels=ancestors, declassified_by=manifest.get("declassified_by"), ) ```