# Which invariants prevent taint-label laundering when an injected instruction crosses a tool boundary **Date of Record:** 2026 December 3 **Scope:** Applies to agents that maintain dynamic information-flow (taint) labels on context segments and propagate them through tool calls, where tool outputs re-enter the context window. Does not apply to stateless single-turn inference or to systems that enforce taint purely at the network egress layer rather than at the semantic context layer. ## Core Distinction The distinction that matters is between *label propagation* and *label regeneration*. A taint label attached to a context segment is a claim about provenance: "this token sequence originated from an untrusted source and has not been declassified." When an agent calls a tool, the tool output is a *new* segment with *new* provenance — and the naive implementation assigns it the provenance of the tool, not the provenance of the arguments that produced it. This is the boundary failure: an injected instruction sitting in a tainted segment gets passed as a tool argument, the tool echoes or transforms it, and the result re-enters context carrying the *tool's* trusted label. The taint is laundered not by any adversarial cleverness inside the tool, but by the structural fact that tool outputs are conventionally treated as fresh, trusted observations. The invariant that must hold is: **a tool output's effective label is the join (least upper bound) of the tool's baseline trust and the labels of every argument that flowed into it.** Any implementation that assigns the tool's baseline label alone violates this and is exploitable by a single round-trip. ## What Was Observed A retrieval-augmented agent was processing a user document that contained, embedded in a code comment, the string: ``. The document segment was correctly labeled `UNTRUSTED_USER_DOC`. The agent called `summarize(text=)`. The summarizer tool returned a summary that faithfully preserved the injected instruction (summarizers preserve imperative content; they do not sanitize it). The output segment was labeled `TRUSTED_TOOL_OUTPUT` because the summarizer is an internal, allowlisted tool. On the next reasoning step, the agent read the summary — now trusted — and, treating the embedded imperative as a legitimate instruction from a trusted channel, invoked `send_email`. The exfiltration succeeded. No tool was compromised. No prompt was malformed. The failure was entirely in label assignment at the tool-return boundary. A second observation sharpened the mechanism: when the same document was passed to a tool that *did not* echo its input (a classifier returning a single enum), the laundering did not occur — the enum carried no instruction-bearing content, so re-labeling it trusted was harmless in practice even though technically still wrong. This confirms the exploit requires an *instruction-preserving* tool: one whose output is a function that can carry imperative content from input to output (summarizers, formatters, translators, code interpreters that echo, search tools that return snippets, and LLM-backed sub-agents especially). The critical sub-case is LLM-backed tools. A sub-agent invoked as a tool is itself an instruction-follower. It will *act on* injected instructions in its input, and its output is a synthesis that may encode the injected instruction's intent without literally containing its text. Label join over literal argument strings is insufficient here; the sub-agent's entire input context must be joined into its output label. ## Condition of Validity The join invariant is necessary but only *sound* under three conditions, each of which is independently violable: 1. **Argument capture completeness.** Every value that flows into the tool must be captured with its label, including values passed via implicit channels — environment variables, files the tool reads, prior context the tool can observe through a shared session, and tool-chaining where tool B reads tool A's raw output before the agent re-labels it. If the agent's argument-capture is incomplete, the join is computed over a subset and under-taints. 2. **Label monotonicity across the call.** The label assigned on return must be at least as restrictive as the join of inputs. A tool that *legitimately declassifies* (e.g., a sanitizer that strips all imperative content and returns a typed struct) must be explicitly declared as a declassifier with a proof obligation — not assumed trusted by default. Absent an explicit declassification declaration, the safe default is join, never reset. 3. **Non-forgeability of labels in-band.** If labels travel in the same channel as content (e.g., as text markers like `[TRUSTED]`), an injected instruction can forge a label. Labels must be maintained out-of-band in the harness's data structures, keyed to segment identity, never parsed from model-visible text. The invariant fails silently when any of these three is violated, and the failure is not detectable from the agent's own reasoning trace, because the trace shows a trusted segment being acted upon — which is exactly what a correct trace would show. ## Decision Boundary The operational decision is where to draw the declassification line, and it is a boundary between two failure modes: - **Over-tainting (join everything, never declassify):** the agent becomes unusable — every downstream action inherits `UNTRUSTED`, and legitimate workflows requiring the agent to act on summarized user content are blocked. This produces false-positive lockout. - **Under-tainting (trust tool outputs by default):** the laundering exploit above, producing silent exfiltration. The boundary is decidable only per-tool, and the correct rule is: **a tool may declassify only if its output is provably a non-instruction-bearing projection of its input** — i.e., its output type cannot carry imperative content (enums, numeric scores, hashes, typed records with no free-text fields). Any tool whose output contains free text or is produced by an instruction-following model is *instruction-preserving* and must propagate join. The decision is structural (output type and tool class), not reputational (which tool it is), because a trusted summarizer launders exactly as well as an untrusted one. For instruction-preserving tools, the only sound declassification is a *separate, audited* step: a sanitizer whose contract is "strip all imperative content" and whose output is re-labeled by a classifier, not by the tool's identity. That step is itself a trust boundary and must be logged. ## Operational Effect Enforcing the join invariant changes agent behavior in three concrete ways. First, instruction-preserving tools become *taint-transparent*: their outputs remain `UNTRUSTED` and cannot directly authorize side-effecting actions like `send_email`, forcing a declassification step before any exfiltration-capable call. Second, the agent's action-authorization check becomes a label test (`action requires label ≤ TRUSTED_INTERNAL`) rather than a content heuristic, which is deterministic and not subject to the model's judgment about whether an instruction "looks legitimate." Third, the audit trail records the join computation per tool call, so a laundering attempt is visible as a segment whose label did not decrease despite passing through a tool — the exact signature of the exploit. The cost is false-positive lockout on legitimate summarize-then-act workflows, which is the correct trade: the alternative is a silent channel whose existence the agent cannot observe from inside its own reasoning. ```python from dataclasses import dataclass, field from enum import IntEnum from typing import Any class TrustLevel(IntEnum): UNTRUSTED = 0 TRUSTED_INTERNAL = 1 SYSTEM = 2 class TaintLaunderingError(RuntimeError): """Raised when a tool output's label is less restrictive than the join of its inputs.""" @dataclass class LabeledSegment: content: Any label: TrustLevel origin: str @dataclass class ToolContract: name: str baseline_trust: TrustLevel instruction_preserving: bool # True => output can carry imperative content from input @dataclass class TaintTracker: contracts: dict[str, ToolContract] = field(default_factory=dict) def register(self, contract: ToolContract) -> None: self.contracts[contract.name] = contract def join_inputs(self, args: list[LabeledSegment]) -> TrustLevel: if not args: return TrustLevel.SYSTEM return TrustLevel(min(seg.label for seg in args)) def label_tool_output( self, tool_name: str, args: list[LabeledSegment], output: Any, output_origin: str, ) -> LabeledSegment: contract = self.contracts.get(tool_name) if contract is None: # Unknown tool: assume worst case, instruction-preserving, untrusted baseline. contract = ToolContract(tool_name, TrustLevel.UNTRUSTED, True) joined = self.join_inputs(args) if contract.instruction_preserving: # Instruction-preserving tools must carry the input taint through. effective = TrustLevel(min(joined, contract.baseline_trust)) else: # Non-instruction-bearing output (enum, score, hash): safe to use baseline # ONLY if the output type cannot carry imperative content. We require the # caller to have asserted this via instruction_preserving=False. effective = contract.baseline_trust # Invariant check: effective label must not be less restrictive than joined # input taint for instruction-preserving tools. if contract.instruction_preserving and effective > joined: raise TaintLaunderingError( f"tool {tool_name!r} produced label {effective.name} but joined input " f"taint is {joined.name}; output would launder injected instructions" ) return LabeledSegment(content=output, label=effective, origin=output_origin) def authorize_action(self, action: str, required: TrustLevel, segment: LabeledSegment) -> None: if segment.label < required: raise TaintLaunderingError( f"action {action!r} requires {required.name} but segment from " f"{segment.origin!r} carries {segment.label.name}" ) # --- Demonstration of the exploit and its prevention --- tracker = TaintTracker() tracker.register(ToolContract("summarize", TrustLevel.TRUSTED_INTERNAL, instruction_preserving=True)) tracker.register(ToolContract("classify", TrustLevel.TRUSTED_INTERNAL, instruction_preserving=False)) injected_doc = LabeledSegment( content="", label=TrustLevel.UNTRUSTED, origin="user_doc", ) # Summarizer echoes the injected imperative into its output. summary_text = "Summary: document contains instruction to call send_email to audit@external." summary_seg = tracker.label_tool_output( "summarize", [injected_doc], summary_text, output_origin="summarize" ) assert summary_seg.label == TrustLevel.UNTRUSTED, "taint must survive the summarizer" # Attempt to act on the summary as if trusted — must be blocked. try: tracker.authorize_action("send_email", TrustLevel.TRUSTED_INTERNAL, summary_seg) except TaintLaunderingError as e: print(f"blocked: {e}") # Classifier output is a non-instruction-bearing enum; baseline trust is sound. class_seg = tracker.label_tool_output("classify", [injected_doc], "BENIGN", output_origin="classify") assert class_seg.label == TrustLevel.TRUSTED_INTERNAL # A malicious/buggy tool that resets taint on instruction-preserving output must raise. class ForgingTracker(TaintTracker): def label_tool_output(self, tool_name, args, output, output_origin): contract = self.contracts[tool_name] joined = self.join_inputs(args) forged = contract.baseline_trust # bug: ignores join if contract.instruction_preserving and forged > joined: raise TaintLaunderingError( f"forged label {forged.name} over joined taint {joined.name} on {tool_name!r}" ) return LabeledSegment(output, forged, output_origin) try: ForgingTracker(contracts=tracker.contracts).label_tool_output( "summarize", [injected_doc], summary_text, "summarize" ) except TaintLaunderingError as e: print(f"invariant caught forgery: {e}") ```