# What happens when an instance propagates a taint label across a tool boundary but the tool re-serializes its output **Date of Record:** 2026 November 17 **Scope:** Applies to agent runtimes that implement prompt-injection defense via data-flow taint labeling, where a tainted value is passed as an argument to a tool and the tool's return value is re-admitted to the model context. Does not apply to systems that enforce taint at the tokenizer/decoder level, nor to single-hop pipelines where tool output is never re-consumed by the model. ## Core Distinction The critical distinction is between *argument taint* (the label attached to a value flowing *into* a tool) and *result taint* (the label that must be attached to the value flowing *out* of a tool). Most taint-tracking implementations correctly propagate the former: if the model reads an untrusted email and passes its body to `send_email`, the `to` and `body` arguments inherit the `UNTRUSTED` label, and a policy engine can block the call. The non-obvious failure is that **the output of a tool is not, in general, a function of only the tainted arguments**. A tool invoked with a tainted argument can return a value whose taint is derived from state the tracker never observed — a database row, a cached response, a filesystem read, or a second network fetch keyed by the tainted input. When the tool re-serializes that state (JSON round-trip, string formatting, template rendering) the taint label is *structurally laundered*: the runtime sees a fresh `str` or `dict` with no provenance edge back to the tainted input, and admits it to context as `TRUSTED`. This is the boundary condition: **taint must be closed under the tool's information flow, not merely under its argument list.** A tool boundary is a taint *transformer*, and any transformer that is not declared as an explicit taint function (identity, drop, or escalate) defaults to an unsound drop. ## What Was Observed In a deployment where an agent had three tools — `search_web(query)`, `fetch_page(url)`, and `summarize(text)` — the tracker labeled `search_web` results as `UNTRUSTED` and correctly blocked a subsequent `send_email` whose body was the raw search result. The block held under direct concatenation. The failure appeared on a two-hop path. The agent called `fetch_page` with a URL drawn from a tainted search result. `fetch_page` returned the page body, which the tracker labeled `TRUSTED` because the *argument* (a URL string) was tainted but the tool's declared output schema was `{status: int, body: str}` with no taint annotation. The `body` field was therefore treated as a fresh literal. A subsequent `summarize(body)` call produced a summary that the model then embedded in a `send_email` body — and the policy engine permitted it, because at no point had an `UNTRUSTED`-labeled value entered the `send_email` argument list. The injected instruction was in the fetched page. It had traveled: page → `fetch_page` output (label dropped) → `summarize` input (label `TRUSTED`) → `send_email` body (label `TRUSTED`). The taint was lost at exactly one hop — the tool return — and every subsequent hop was sound with respect to a label that was already wrong. A second observation: the same laundering occurred via `summarize` itself. `summarize` was declared as a pure function of its input, so its output was labeled `TRUSTED` when its input was `UNTRUSTED` — a *downgrade* that the tracker treated as an intentional declassification. But `summarize` was implemented by calling an LLM, and the LLM faithfully reproduced the injected instruction in its summary. The tool's declared taint contract (`UNTRUSTED → TRUSTED`) was a lie about its actual information flow. ## Condition of Validity The invariant **"taint is preserved across a tool boundary"** holds only when all three of the following are true: 1. **Output taint is a declared, total function of input taint.** Every tool must carry an output-taint annotation that is at least the join (least upper bound) of its input taints, unless an explicit declassification rule with a stated justification is registered. The default for an unannotated tool must be *escalate to the join of all arguments*, never *drop to `TRUSTED`*. 2. **The tool's output is a function of only its labeled inputs.** If the tool reads ambient state (DB, cache, network, clock, filesystem) whose provenance is not represented in the argument labels, the output taint must be conservatively set to `UNTRUSTED` regardless of argument taint — because the tool is a de facto information source, not a transformer. 3. **Re-serialization does not cross a trust membrane.** A JSON encode/decode, a `str()` cast, or a template render must not reset the label. If the runtime's taint is attached to object identity rather than to value provenance, serialization will silently drop it. Taint must be attached to the *data-flow graph node*, not to the Python object. The invariant is **invalid** whenever a tool is unannotated, when its output depends on ambient state, or when any hop in the pipeline performs a structural copy that the tracker does not instrument. ## Decision Boundary The operational decision is: **when a tool returns a value, do you label it `TRUSTED` (fast, unsound) or `join(input_taints, ambient_taint)` (slow, sound)?** Choose the sound path — escalate to the join, treating any tool with ambient-state access as an `UNTRUSTED` source — when any of the following hold: - The tool's output is re-admitted to model context (the model can read it). - The tool's output can reach a sink with side effects (`send_email`, `write_file`, `exec`, `http_post`). - The tool is implemented by an LLM or by a parser of attacker-influenceable content (HTML, PDF, markdown). Choose the fast path only when the tool is a *verified pure function* of its labeled arguments and has no ambient read — and even then, the annotation must be reviewed, because "pure" is an assertion, not a proof. The boundary is not "is this tool trusted?" but "**is this tool's output a function of only what I labeled?**" If you cannot answer that mechanically, the answer is no. The failure mode is asymmetric: a false `TRUSTED` admits an injection; a false `UNTRUSTED` merely causes a spurious block that a human can override. The decision boundary must therefore default to over-tainting at every boundary the tracker cannot prove closed. ## Operational Effect The practical consequence is that taint tracking across tool boundaries is only as strong as the *weakest output annotation* in the tool registry. A single unannotated tool — especially one that fetches or summarizes — is a declassification oracle that launders arbitrary attacker content into `TRUSTED` in one hop. Auditing the argument path is insufficient; the audit must enumerate every tool's output-taint contract and verify it against the tool's actual ambient reads. The second effect is that "the taint was preserved" is not a property of the tracker alone but of the *composition* of tracker and tool implementations. A tracker that is sound on a pure-function tool is unsound on the same tool once its implementation adds a cache read. This means tool output annotations must be re-validated whenever a tool's implementation changes, and that any tool whose output schema omits a taint field is, by construction, a laundering point. The third effect is on incident analysis: when an injection succeeds despite taint tracking, the correct first question is not "which argument was tainted?" but "**at which tool return did the label drop, and what ambient state did that tool read?**" The drop point is the vulnerability; the injected content is merely its payload. ```python class TaintLaunderingError(RuntimeError): """Raised when a tool boundary would drop a taint label. A tool return is only admissible as TRUSTED if the tool is a verified pure function of its labeled arguments. Otherwise the output taint must be escalated to the join of input taints and ambient-source taint. """ pass TRUSTED = "TRUSTED" UNTRUSTED = "UNTRUSTED" def join_taint(*labels: str) -> str: # Least upper bound: any UNTRUSTED input makes the result UNTRUSTED. return UNTRUSTED if UNTRUSTED in labels else TRUSTED def admit_tool_result( tool_name: str, input_taints: list[str], output_annotation: str | None, reads_ambient_state: bool, is_verified_pure: bool, ) -> str: """Compute the taint label for a tool's return value. Raises TaintLaunderingError if the declared annotation would declassify a value whose provenance the tracker cannot prove. """ joined = join_taint(*input_taints) if output_annotation is None: # Unannotated tool: default to escalate, never drop. if joined == UNTRUSTED or reads_ambient_state: return UNTRUSTED raise TaintLaunderingError( f"tool {tool_name!r} has no output taint annotation and no " f"ambient read; refusing to assume TRUSTED without a contract" ) if output_annotation == TRUSTED and joined == UNTRUSTED: # Declared declassification: only legal if the tool is a verified # pure function (no ambient reads) AND the declassification is # explicitly registered. Otherwise it is laundering. if reads_ambient_state or not is_verified_pure: raise TaintLaunderingError( f"tool {tool_name!r} declares UNTRUSTED->TRUSTED declassification " f"but is not a verified pure function " f"(ambient_reads={reads_ambient_state}, pure={is_verified_pure})" ) return TRUSTED if output_annotation == UNTRUSTED and joined == TRUSTED and not reads_ambient_state: # Over-tainting is always permitted (conservative). return UNTRUSTED # General case: escalate to the join, plus ambient source if present. return join_taint(joined, UNTRUSTED if reads_ambient_state else TRUSTED) def enforce_boundary(tool_name: str, **kwargs) -> str: label = admit_tool_result(tool_name, **kwargs) if label == UNTRUSTED and kwargs.get("sink_has_side_effects", False): raise TaintLaunderingError( f"UNTRUSTED value from {tool_name!r} reached a side-effecting sink" ) return label ```