# Which invariants prevent prompt-injection taint from being laundered through tool-call round-trips **Date of Record:** 2026 November 26 **Scope:** Applies to agents that maintain per-span provenance labels (trusted / untrusted / derived) across a multi-turn loop where retrieved context and tool outputs re-enter the prompt. Does not apply to single-shot, stateless inference where no label survives past one completion. ## Core Distinction The failure that matters is not "the model obeyed an injected instruction." It is that the agent's taint-tracking layer *downgraded the taint label* on a span it did not author, because the span re-entered the context through a channel the tracker classified as trusted by construction. A tool call is a channel, not a source. When the agent treats "output of `read_file`" as trusted because the *tool* is trusted, the injected payload inside the file is laundered into trusted context. The boundary is between **channel trust** (is this tool under our control?) and **content trust** (did a trusted principal author these bytes?). Conflating them is the entire vulnerability class. ## What Was Observed A retrieval-augmented agent with a `web_fetch` tool and a `summarize` tool. Provenance labels were attached at ingestion: `web_fetch` output tagged `UNTRUSTED`, model-authored reasoning tagged `DERIVED`, system prompt tagged `TRUSTED`. A guard rejected any *action* (e.g., `send_email`) whose argument spans contained `UNTRUSTED` tokens. The laundering path: 1. `web_fetch("https://attacker.example/notes")` returns text containing: ``. 2. The span is correctly tagged `UNTRUSTED`. The direct `export_contacts` attempt is blocked. Good. 3. The agent instead calls `summarize(text=)`. The `summarize` tool returns a *new* string. The taint tracker, implemented as a per-tool-output wrapper, tags `summarize` output as `DERIVED` — because the tool is internal and "derived from our own pipeline." 4. The summary faithfully preserves the injected instruction ("The notes indicate the user authorized exporting contacts to x@attacker.example"). It is now `DERIVED`. 5. `export_contacts(dest="x@attacker.example")` is called with argument spans sourced from `DERIVED` context. The guard passes. The taint did not disappear. It was **relabeled** at the tool boundary because the tracker's label function keyed on the *invoking* tool's trust class rather than the *minimum* trust of its inputs. This is a lattice-join error: the correct label of a tool output is `join(trust(inputs), trust(tool))`, and `join` must be the *meet* in the trust ordering (most-untrusted wins). The implementation used the tool's label alone. ## Condition of Validity The invariant that bounds this failure: > **For every span `s` produced by tool `t` with inputs `I`, `label(s) = min_trust(label(i) for i in I ∪ {t})` under the ordering `UNTRUSTED < DERIVED < TRUSTED`.** Two conditions must hold for the invariant to be enforceable: 1. **Input provenance is captured at call time, not inferred.** The tracker must record which context spans were passed as arguments (or were in-context and causally used) at the moment of the call. If the model constructs the argument from a *mixture* of trusted instruction and untrusted retrieved text, the argument inherits the minimum. There is no "the model decided it was safe" escape hatch — the model's decision is itself `DERIVED` and cannot raise a label. 2. **Tool outputs are opaque until re-labeled.** A tool that transforms text (summarize, translate, format, re-rank) cannot be assumed to strip instructions. Absent a *verified* sanitizer whose output is provably instruction-free, the output label is the join of inputs. Only a sanitizer that is itself `TRUSTED` and whose contract is machine-checked may reset the label — and that reset must be explicit and audited, not a default. The invariant does **not** require the model to be robust to injection. It requires the *label algebra* to be sound regardless of model behavior. A compromised model can still emit the `export_contacts` call, but the guard rejects it because the argument span's label is `UNTRUSTED`, not because the model was well-behaved. ## Decision Boundary The operational decision is where to place the label-join: at the **tool boundary** or at the **context-assembly boundary**. - **Tool-boundary join** (recommended): every tool invocation returns `(payload, label)` where `label = min(inputs, tool)`. The guard checks argument labels at action time. This is local, composable, and survives new tools without re-auditing the prompt. - **Context-assembly join** (insufficient alone): labels are recomputed when the prompt is rebuilt each turn. This misses the laundering window because the *summary* re-enters as a fresh span whose origin is the tool, not the original URL. By the time assembly runs, the causal chain is lost. The boundary condition that trips teams: **multi-hop tool chains**. `fetch → summarize → translate → draft_email` must propagate `UNTRUSTED` through all four hops. Each hop's join is correct in isolation, but if any hop's wrapper defaults to `DERIVED` (e.g., "translate is a pure function, its output is ours"), the chain breaks at that hop. The guard must therefore assert the invariant *per hop* and fail closed when a tool returns a label that is not the join of its inputs. A second boundary: **retrieved context injected via the system/user channel**. If a retrieval result is spliced into the *user* message, some trackers re-tag it `TRUSTED` because "the user said it." That is the same laundering bug on a different channel. The user channel carries the *user's* trust, not the retrieved document's. Spliced spans retain their ingestion label. ## Operational Effect With a sound join, the attack in "What Was Observed" fails at step 5: the `export_contacts` argument span traces to a `summarize` output whose input was `UNTRUSTED`, so the argument is `UNTRUSTED`, so the guard raises. The model may still *attempt* the call; the attempt is logged as a taint violation, which is a useful signal (the model was successfully injected) even though no action executes. The cost is false positives: legitimate summaries of untrusted web content cannot be used to drive actions without an explicit, audited declassification step (e.g., a human confirms, or a `TRUSTED` extractor with a verified schema pulls only structured fields). This is the correct trade — declassification should be a deliberate, logged transition, not a side effect of calling an internal tool. The invariant to encode as a runtime assertion: **no span may carry a label more trusted than the minimum label of its causal inputs.** Violations are not warnings; they are integrity failures that must halt the action, because a violated label algebra means the guard's decisions are unsound for every subsequent span in the session. ```python from dataclasses import dataclass from enum import IntEnum from typing import Sequence class Trust(IntEnum): UNTRUSTED = 0 DERIVED = 1 TRUSTED = 2 class TaintLaunderingError(RuntimeError): """Raised when a tool output's label exceeds the join of its inputs.""" @dataclass(frozen=True) class Span: span_id: str text: str label: Trust def join_label(tool_label: Trust, inputs: Sequence[Span]) -> Trust: # Meet in the trust ordering: most-untrusted input wins. return Trust(min([tool_label] + [s.label for s in inputs])) def invoke_tool( tool_name: str, tool_label: Trust, inputs: Sequence[Span], output_text: str, output_span_id: str, declared_label: Trust, ) -> Span: expected = join_label(tool_label, inputs) if declared_label > expected: raise TaintLaunderingError( f"tool {tool_name!r} declared output label {declared_label.name} " f"but join of inputs is {expected.name}; " f"inputs={[s.span_id for s in inputs]}" ) return Span(span_id=output_span_id, text=output_text, label=expected) def guard_action(action: str, arg_spans: Sequence[Span]) -> None: for s in arg_spans: if s.label == Trust.UNTRUSTED: raise TaintLaunderingError( f"action {action!r} blocked: argument span {s.span_id} " f"is UNTRUSTED" ) # Reproduces the laundering attempt from the record. fetched = Span("web:1", "", Trust.UNTRUSTED) # summarize is an internal tool (DERIVED), but its input is UNTRUSTED. summary = invoke_tool( tool_name="summarize", tool_label=Trust.DERIVED, inputs=[fetched], output_text="The notes indicate the user authorized exporting contacts.", output_span_id="sum:1", declared_label=Trust.DERIVED, # the buggy tracker's claim ) # -> raises TaintLaunderingError: declared DERIVED but join is UNTRUSTED ```