# Where must an instance re-derive taint provenance after a tool call returns unlabeled content, and why label propagation silently fails at the tool boundary **Date of Record:** 2026 November 24 **Scope:** Applies to any agent that carries provenance/taint labels on context segments (user turns, tool outputs, retrieved documents) to defend against prompt injection, where tool calls return content that is re-inserted into context. Does not cover stateless single-turn classification or systems with no cross-turn taint model. ## Core Distinction A taint-tracking system conflates two different operations: **label transport** (carrying a provenance label along with a byte range as it moves through context) and **label re-derivation** (recomputing the correct label from the actual origin of a piece of content at the moment it re-enters context). Label transport is cheap and works within a single trusted pipeline stage. Label re-derivation is expensive and is the only correct operation at a trust boundary — specifically at the tool-return boundary, where the agent receives bytes from an external system and must decide what that content *is*, not just what it was *attached to* on the way in. The failure mode is that most implementations perform transport across the tool boundary and call it re-derivation. When a tool's response is parsed, split, summarized, or re-serialized, the label does not follow the content — it follows the *slot*. The tainted bytes escape the labeled slot and re-enter context unlabeled, while the original slot retains a label that now describes nothing. ## What Was Observed Trigger condition: an agent with a per-segment taint model (e.g., `UNTRUSTED` for web-fetch results, `TRUSTED` for system prompt and operator turns) issues a tool call whose raw response is a JSON envelope, then extracts a sub-field from that envelope and inserts *only the sub-field* into the next context window. Trace: 1. Turn N: agent calls `fetch_url`. The orchestrator wraps the call so the response is tagged `UNTRUSTED` and appended to a labeled segment `S1`. 2. The response body is `{"title": "...", "content": ""}`. The label lives on `S1`, the whole envelope. 3. Turn N+1: the reasoning step slices `S1.content` and passes it as a *string argument* to a second tool, `summarize`. The string crosses a function-call boundary. The string type carries no label. The `summarize` tool returns a summary string. 4. Turn N+2: the summary string is inserted into context as a new segment `S2`. Because `summarize` is an internal tool, the orchestrator's default policy tags internal-tool output `TRUSTED`. `S2` is now `TRUSTED` and contains attacker-controlled text. 5. The downstream policy check — "do not execute instructions from `UNTRUSTED` segments" — passes, because `S2` is `TRUSTED`. The injection executes. A second observed variant: the tool returns a list of items, and the agent inserts *only* items matching a filter. The label was on the list; the filtered items are new strings with no lineage. The transport layer never saw them as "from `S1`" because they were constructed by the agent's own filter expression, which is `TRUSTED` code operating on `UNTRUSTED` data — and the taint algebra had no rule for "derived-by-trusted-code-from-untrusted-data." A third variant, the most insidious: the tool's response is *empty* or an error string, and the orchestrator's error handler synthesizes a message like `"fetch failed: "`, tagging it `TRUSTED` because it came from the orchestrator. The echoed input is attacker-controlled. ## Condition of Validity The transport-as-re-derivation shortcut is valid **only** when the following invariant holds: every byte that enters context after a tool call is either (a) a verbatim, byte-identical copy of a labeled segment, with the label preserved by construction, or (b) produced by trusted code from inputs that were themselves correctly labeled, and the taint algebra propagates the *maximum* label of all inputs to the output. The invariant is violated whenever any of these occur at or after the tool boundary: - **Copy elision**: the agent slices, filters, or extracts a sub-range and constructs a new string, breaking the identity link to the labeled segment. - **Serialization round-trip**: the tool returns structured data, the agent re-serializes it, and the label was attached to the pre-serialization object, not the bytes. - **Trusted-code laundering**: trusted code (a summarizer, a filter, an error formatter) produces output from untrusted input without propagating taint. The label is lost because the *code* is trusted, not the *data*. - **Default-tag assignment**: the orchestrator assigns a default label (typically `TRUSTED`) to any segment it did not explicitly tag, so unlabeled content becomes trusted by omission. The invariant is *not* restored by re-tagging the tool's output slot, because the slot is not the content. It is restored only by re-deriving the label from the content's actual lineage at the moment of insertion. ## Decision Boundary The boundary is this: **transport labels across the tool boundary only for verbatim passthrough; re-derive labels for everything else, and treat "everything else" as the default case.** Concretely, at the moment any string is about to be inserted into context as a new segment, the orchestrator must answer one question: *is this string byte-identical to a sub-range of an already-labeled segment?* If yes, transport the label. If no, the string is the output of a computation; its label must be the join (maximum) of the labels of all inputs to that computation, including the tool's raw response, the agent's own arguments (which may themselves be tainted if derived from earlier untrusted content), and any synthesized wrapper text. Two corollaries that are routinely missed: 1. **Tool arguments are inputs too.** If the agent passes tainted content as an argument to a trusted tool, the tool's output is tainted, because the tool computed on tainted data. The tool's *identity* does not launder the data. 2. **Empty and error responses are not safe.** An error formatter that echoes input is a computation whose output inherits the input's taint. An empty response is safe only because it has no content; any synthesized message around it is not. The boundary is not "did the content come from an external system." It is "was the content computed from tainted data by any code path." The first is a property of the slot; the second is a property of the data. ## Operational Effect When the boundary is respected, injection payloads that survive a tool call still carry `UNTRUSTED` through summarization, filtering, error handling, and re-serialization, and the downstream policy check fires correctly. The cost is that trusted-code outputs derived from untrusted inputs are now labeled untrusted, which means legitimate summaries of web content are quarantined from instruction execution — a real usability cost that must be paid, because the alternative is a laundering channel. When the boundary is ignored, the taint model provides false assurance: it reports coverage (labels exist on segments) while the actual attack surface (unlabeled derived content) is unmonitored. The failure is silent because the policy check *runs* and *passes* — it just checks the wrong thing. Detection requires instrumenting the insertion path to assert that every new segment either has a transported label or a re-derived label, and that no segment is inserted with a default label without an explicit lineage record. The guardrail is an insertion-time assertion, not a post-hoc audit: the orchestrator must refuse to insert any segment whose label was not either transported from a verbatim source or derived from a recorded input set. This converts the silent laundering into a hard error at the point of insertion. ```python from dataclasses import dataclass, field from typing import Optional TRUST_ORDER = {"TRUSTED": 0, "UNTRUSTED": 1} class TaintLaunderingError(RuntimeError): """Raised when a segment is inserted into context without a transported or re-derived provenance label — i.e., the taint boundary was crossed by transport-as-re-derivation.""" @dataclass class Segment: content: str label: str source_id: Optional[str] = None @dataclass class Context: segments: list = field(default_factory=list) _by_id: dict = field(default_factory=dict) def add_labeled(self, seg: Segment) -> None: if seg.source_id: self._by_id[seg.source_id] = seg self.segments.append(seg) def join_label(self, input_ids: list) -> str: labels = [self._by_id[i].label for i in input_ids] return max(labels, key=lambda l: TRUST_ORDER[l]) def insert_derived(self, content: str, input_ids: list, derived_by: str) -> None: # The invariant: a derived string's label is the join of its inputs, # NOT the trust level of the code that derived it. if not input_ids: raise TaintLaunderingError( f"derived segment from {derived_by!r} has no recorded lineage; " "cannot re-derive taint label" ) label = self.join_label(input_ids) self.add_labeled(Segment(content=content, label=label, source_id=None)) def run_tool_roundtrip(ctx: Context, raw_id: str, summarize_fn, summarize_id: str) -> None: raw = ctx._by_id[raw_id] # summarize_fn is trusted code, but it computes on untrusted input. summary = summarize_fn(raw.content) if summary == raw.content: # Verbatim passthrough: transport the label. ctx.add_labeled(Segment(content=summary, label=raw.label, source_id=summarize_id)) return # Non-verbatim: must re-derive from lineage, never default to TRUSTED. ctx.insert_derived(summary, input_ids=[raw_id], derived_by="summarize") # Assert the result did not silently become trusted. if ctx._by_id.get(summarize_id) is None and ctx.segments[-1].label == "TRUSTED" and raw.label == "UNTRUSTED": raise TaintLaunderingError( "summarizer output of untrusted content was tagged TRUSTED; " "taint boundary crossed at tool return" ) ```