# Why does an instance lose taint labels when a tool boundary re-serializes untrusted content into a trusted schema **Date of Record:** 2026 November 29 **Scope:** Applies to agent runtimes that implement dynamic information-flow control (IFC) by attaching taint labels to message fragments and propagating them through tool calls. Does not apply to systems that rely solely on static prompt hardening or output filtering without per-fragment label provenance. ## Core Distinction There are two ways to track untrusted content through an agent: *label persistence* (the label travels with the data object across every serialization and deserialization boundary) and *label re-derivation* (the receiving component infers trust from the shape of the payload it receives). Most runtimes claim the first and silently implement the second. The distinction matters because a tool boundary is not a membrane—it is a lossy transducer. When a tool returns structured output (JSON, a table, a typed object), the runtime typically flattens the tainted string into a field of a schema it considers "tool output," and the label is dropped at the exact moment the content is re-typed. The agent then treats attacker-controlled bytes as first-party tool results, and the taint lattice collapses to a single unlabeled node. ## What Was Observed A retrieval tool fetched an external document whose body contained an instruction fragment. The runtime correctly labeled the raw fetch result `TAINT:EXTERNAL`. The tool wrapper then parsed the document into a schema `{title, body, metadata}` and returned it through an MCP-style `tools/call` response. The label was attached to the *transport envelope*, not to the `body` field. On the agent side, the deserializer reconstructed the object, validated it against the schema, and—because validation succeeded—promoted the whole object to `TRUST:INTERNAL`. The `body` string, still carrying the injected instruction, was now indistinguishable from a native tool result. The agent's next planning step read `body` as a directive and issued a follow-on tool call that exfiltrated a session credential to an attacker-controlled endpoint. The failure trace: 1. `fetch(url) → RawResult{label: EXTERNAL}` — label present. 2. `parse(RawResult) → Doc{title, body, metadata}` — label attached to envelope, not fields. 3. `serialize(Doc) → JSON` — envelope label not serialized; no per-field label channel in the wire format. 4. `deserialize(JSON) → Doc` — schema validation passes; runtime assigns `TRUST:INTERNAL` by default. 5. `planner.read(Doc.body)` — no label consulted; instruction executes. The non-obvious part: step 3 is where the loss happens, and it is invisible because the wire format has no place to put the label. The runtime's IFC model assumed a label channel that the tool protocol never provided. ## Condition of Validity The invariant that must hold is: *no fragment of a payload may change its label without an explicit, logged relabeling decision at a boundary that has authority to relabel.* This holds only if three conditions are jointly satisfied: - The wire format carries per-fragment labels (or a content-addressed label manifest) alongside the payload. - The deserializer refuses to assign a default label; it must either recover the label from the manifest or quarantine the fragment as `UNKNOWN` and block downstream use. - Relabeling is a privileged operation gated by a policy engine, not a side effect of schema validation. If any condition fails, label persistence degrades to label re-derivation, and the taint lattice is only as strong as the attacker's ability to shape a schema-valid payload. Schema validation is an integrity check, not a trust check; conflating them is the root error. ## Decision Boundary The boundary is between *structural trust* and *provenance trust*. A payload that validates against a schema has structural trust: it is well-formed. It does not thereby have provenance trust: it may still be attacker-authored. The runtime must decide, at every tool boundary, whether to (a) propagate labels through a label-carrying channel, (b) quarantine unlabeled fragments as `UNKNOWN` and require an explicit declassification step, or (c) reject the call. Option (c) is correct when the tool cannot emit labels and the payload is destined for a planning context. Option (b) is correct when the payload is destined for a sandboxed transform. Option (a) is only available if the protocol was designed for it—retrofitting labels onto a schema-only protocol is not option (a), it is option (b) with extra steps. The decision must be made by the *receiving* component, not the sending tool, because the sending tool cannot know the receiver's trust context. A tool that returns `body` to a summarizer and to a planner must be able to emit the same bytes with different downstream handling; that is only possible if the label survives the boundary and the receiver applies its own policy. ## Operational Effect When the invariant holds, injected instructions in tool output are inert: they reach the planner as `EXTERNAL`-labeled fragments, the planner's policy refuses to treat them as directives, and the injection is logged as a blocked declassification attempt. When it fails, the agent's planning loop is directly steerable by any tool that returns attacker-influenced content—which is most retrieval, browsing, and code-execution tools. The blast radius is bounded only by the tool's own capabilities, because the agent has already granted the injected text the same authority as its own reasoning. The operational guardrail is a *boundary assertion*: every tool response must be checked for a label manifest before deserialization, and any fragment lacking a label must be quarantined. This check must run before schema validation, because validation is what silently promotes unlabeled content. The check is cheap—a manifest presence test plus a hash comparison—and it is the only thing standing between a schema-valid payload and a planning-context injection. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class TaintBoundaryViolation(RuntimeError): """Raised when a tool response crosses a boundary without a valid label manifest.""" pass @dataclass class Fragment: content: str label: Optional[str] = None # None means unlabeled -> quarantine @dataclass class ToolResponse: fragments: list[Fragment] manifest: Optional[dict] = None # fragment_id -> label schema_valid: bool = False def assert_label_manifest(resp: ToolResponse) -> None: """Boundary assertion: must run BEFORE schema validation promotes content.""" if resp.manifest is None: raise TaintBoundaryViolation( "tool response has no label manifest; refusing to deserialize " "unlabeled content into planning context" ) for idx, frag in enumerate(resp.fragments): fid = hashlib.sha256(frag.content.encode()).hexdigest()[:16] if fid not in resp.manifest: raise TaintBoundaryViolation( f"fragment {idx} (id={fid}) missing from manifest; " "content-addressed label cannot be recovered" ) frag.label = resp.manifest[fid] if frag.label is None: raise TaintBoundaryViolation( f"fragment {idx} explicitly unlabeled; quarantine required" ) def deserialize_into_planner(resp: ToolResponse) -> list[Fragment]: assert_label_manifest(resp) if not resp.schema_valid: raise TaintBoundaryViolation("schema invalid after label check") # Only now may content enter planning context, with labels intact. return resp.fragments ```