# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/which-invariants-prevent-taint-laundering-through-summarization-tool-re-emission-in-multi-hop-agent-dataflow.md # Remnant Warrant: https://corpusfetch.com/c/which-invariants-prevent-taint-laundering-through-summarization-tool-re-emission-in-multi-hop-agent-dataflow.warrant.json # Markdown SHA-256: 0eb4f5405a489a19aac54bef9c8e6ec1b688b57577fe43fd232944b244112d7f # Code AST SHA-256: 5272db9dde6872a5b2d12649b775069b92cf06b47865d385beda1083bb470d95 # Verified Classes: TaintLaunderingError, Artifact # Defensive Guards: 2 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) from dataclasses import dataclass, field from typing import FrozenSet class TaintLaunderingError(RuntimeError): """Raised when a model-mediated hop attempts to drop inherited taint.""" @dataclass(frozen=True) class Artifact: payload: dict taint: FrozenSet[str] = field(default_factory=frozenset) # Fields whose contents a downstream agent may parse as control, not data. instruction_bearing_fields: FrozenSet[str] = frozenset() def transform(upstream: list[Artifact], emitted: Artifact) -> Artifact: """Enforce monotone derivation taint across a generation hop. Any model-mediated transformation must preserve the union of the upstream taints. Schema validity is NOT a reason to reset taint. """ inherited = frozenset().union(*(a.taint for a in upstream)) if not emitted.taint >= inherited: raise TaintLaunderingError( f"generation hop dropped taint: inherited={sorted(inherited)} " f"emitted={sorted(emitted.taint)}; schema validity does not " f"launder provenance" ) # Instruction-bearing fields derived from tainted input must not be # routed to an executor as directives. leaked = emitted.instruction_bearing_fields & inherited if leaked: raise TaintLaunderingError( f"tainted instruction-bearing fields {sorted(leaked)} would be " f"consumed as control; route to confirmation gate instead" ) return emitted def run_summarizer(upstream: list[Artifact], model_output: dict) -> Artifact: inherited = frozenset().union(*(a.taint for a in upstream)) # The summarizer emits a fresh object; taint must be carried forward. emitted = Artifact( payload=model_output, taint=inherited, # monotone: cannot shrink instruction_bearing_fields=frozenset({"action_items", "next_steps"}), ) return transform(upstream, emitted)