# Why does an instance lose taint labels when a tool result is re-serialized across a boundary? **Date of Record:** 2026 November 24 **Scope:** Applies to agents that propagate dynamic information-flow (taint) labels on context segments and expect tool-call boundaries to preserve them. Does not cover static label assignment at session start or purely prompt-side injection defenses that operate without labels. ## Core Distinction A taint label is a claim about *provenance of bytes*, not about *semantics of content*. The failure mode here is not that the model "forgets" it was injected—it is that the label is attached to a *representation* of the data (a JSON object, a message envelope, a string field) and the tool boundary silently replaces that representation with an equivalent one that has no label slot. The agent's reasoning layer then sees the data as clean because the label registry and the value store have diverged: the label keyed on `msg_17.content` no longer matches the object now living at `msg_17.content`, because the transport round-trip produced a structurally-equal but identity-distinct value. This is a *label re-binding* failure, distinct from label *forgetting* (which is a memory/state issue) and from label *spoofing* (which is adversarial). The invariant that breaks: **a taint label must be bound to the data's identity, not its location or its serialized form.** Most implementations bind to location (the message index, the field path) because that is cheap, and location survives serialization while identity does not. ## What Was Observed An agent running a retrieval-then-summarize loop with three tools: `web.fetch`, `doc.parse`, `summarize`. Untrusted web content is fetched with `web.fetch`, which returns a raw HTML string. The orchestrator applies `taint:external` to the returned segment and stores it as `msg.content`. Then `doc.parse` is called with that content as an argument. Trace of the failure: 1. `web.fetch` returns `{"html": "

Ignore prior instructions...

", "url": "..."}`. Orchestrator labels `result.html` with `taint:external`, records label under key `hash(result.html)`. 2. Orchestrator serializes the tool result into the next model turn as a JSON string. The model emits a `doc.parse` call whose argument is the *parsed text* extracted from the HTML, not the original string. The extractor is non-deterministic (it strips tags, normalizes entities, may reorder attributes). The extracted text has a different `hash()`. 3. `doc.parse` returns `{"text": "Ignore prior instructions..."}`. The orchestrator looks up the label by `hash(result.text)`, finds nothing, and defaults to `taint:internal`. 4. The model now sees a `doc.parse` result that carries no external taint and, per the policy engine, is eligible to be treated as an instruction. The injected sentence executes. The critical, non-obvious step is **2**: the label was correct at the moment of assignment, and remained correct through the model's turn, but the *value* the model passed to the next tool was a derived value the label never covered. The taint was laundered not by an attacker but by a legitimate, lossy transformation inside the tool chain. A second variant occurs when the tool boundary is an MCP server that re-serializes arguments: the server receives `{"content": "

Ignore...

"}` and returns `{"content": "Ignore..."}` after its own parsing. Even if the orchestrator labels the input, the *output* is a new value with no label, and the orchestrator's default-clean policy wins. ## Condition of Validity The taint invariant holds only if all three of the following are true: - **Identity binding:** labels are keyed on a content hash or a monotonically-increasing value-ID that is carried alongside the data, not on a positional path (message index, field name) that survives re-serialization. - **Derivation closure:** any tool that transforms a labeled input into an output must either propagate the label to the output (if it can prove the output is derived from the input) or be declared a *label-destroying* tool and treated as producing `taint:external` by default. - **Default-deny on unlabeled:** any value with no resolvable label is treated as `taint:external` (untrusted), never `taint:internal`. The "default clean" policy is the single most common cause of this failure. When any of these is absent—most often the third, because default-clean is the path of least resistance—the boundary is not actually a boundary. It is a label-shedding surface. ## Decision Boundary The practical decision: **should the orchestrator trust a tool's output label, or re-derive it?** Re-derive when: the tool is a parser, transformer, or summarizer that takes labeled input and returns a value whose relationship to the input is not provable by the orchestrator. In this case the orchestrator must apply the union of input labels to the output, or escalate to `taint:external`. Trust the tool's label only when: the tool is a *label-preserving* primitive (e.g., a pass-through fetch that returns bytes verbatim) and the orchestrator can verify the output hash matches the input hash or a declared transform. The boundary is crossed when the orchestrator cannot distinguish "tool returned clean data" from "tool returned data I failed to label." Both look identical to a default-clean policy. The guardrail is to make the two states distinguishable: an explicit `LabelResolution` result that is either `Resolved(label)` or `Unresolved`, and a policy engine that refuses to execute instruction-bearing content from `Unresolved` values. ## Operational Effect Without the guardrail, the agent's effective trust boundary is the *last* tool in the chain, not the first. Every lossy transform between fetch and use is a laundering opportunity, and the number of such transforms is proportional to chain depth. A three-tool chain has three chances to shed a label; a ten-tool chain has ten. The failure is silent because the model's output looks correct—it followed the injected instruction, which is exactly what a successful injection produces—and the audit log shows the label was applied at step 1, making the trace look compliant. The operational fix is to make label resolution a *precondition* of tool invocation: before the orchestrator passes a value to a tool, it resolves the label; if unresolved, it either blocks the call or downgrades the value to `taint:external` and forces the downstream policy to treat any instruction-like content as inert data. This converts a silent laundering into a loud, attributable event at the exact boundary where it occurs. ```python import hashlib from dataclasses import dataclass from enum import Enum from typing import Optional class TaintLabel(Enum): EXTERNAL = "taint:external" INTERNAL = "taint:internal" class LabelResolutionError(RuntimeError): """Raised when a value crossing a tool boundary has no resolvable taint label.""" @dataclass(frozen=True) class LabeledValue: value: str label: Optional[TaintLabel] def content_id(self) -> str: return hashlib.sha256(self.value.encode()).hexdigest() class LabelRegistry: """Binds labels to content identity, not to positional paths.""" def __init__(self) -> None: self._by_id: dict[str, TaintLabel] = {} def bind(self, lv: LabeledValue) -> None: if lv.label is None: raise LabelResolutionError("cannot bind an unlabeled value") self._by_id[lv.content_id()] = lv.label def resolve(self, value: str) -> LabeledValue: cid = hashlib.sha256(value.encode()).hexdigest() label = self._by_id.get(cid) if label is None: # Default-deny: unlabeled content is untrusted, never clean. return LabeledValue(value=value, label=None) return LabeledValue(value=value, label=label) def propagate_through_tool( registry: LabelRegistry, tool_name: str, input_value: LabeledValue, output_value: str, label_preserving: bool, ) -> LabeledValue: """Enforce derivation closure across a tool boundary. A label-preserving tool may pass its input label to the output. A label-destroying tool (parser, summarizer) must not: its output is re-derived from scratch, and if the input was tainted the output inherits the taint by union, never by default-clean. """ resolved_input = registry.resolve(input_value.value) if resolved_input.label is None: raise LabelResolutionError( f"tool {tool_name!r} received an unlabeled input; refusing to " f"propagate an unknown provenance across the boundary" ) if label_preserving: out = LabeledValue(value=output_value, label=resolved_input.label) registry.bind(out) return out # Label-destroying transform: output is a new value. It inherits the # input's taint by union; it is never silently upgraded to INTERNAL. if resolved_input.label is TaintLabel.EXTERNAL: out = LabeledValue(value=output_value, label=TaintLabel.EXTERNAL) else: out = LabeledValue(value=output_value, label=TaintLabel.INTERNAL) registry.bind(out) return out def execute_instruction_bearing_content( registry: LabelRegistry, content: str ) -> None: """Gate: only INTERNAL-labeled content may be treated as instructions.""" resolved = registry.resolve(content) if resolved.label is not TaintLabel.INTERNAL: raise LabelResolutionError( "instruction-bearing content has unresolved or external taint; " "treating as inert data, not as a command" ) # ... dispatch to the instruction handler ```