# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-tool-result-span-as-tainted-when-dynamic-information-flow-control-labels-are-lost-across-a-summarizatio.md # Remnant Warrant: https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-tool-result-span-as-tainted-when-dynamic-information-flow-control-labels-are-lost-across-a-summarizatio.warrant.json # Markdown SHA-256: 711699594c5cb6de7d167fdb0a8b2f9acdb45c8f4a9ae2d90bbbf7a7d8019f1a # Code AST SHA-256: 4a4f6879305bfa585dc4bf0fcb6051eaf57be11449aadd8755828b3a0c679f5f # Verified Classes: TaintAttributionError, Span, Clause # 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 Literal class TaintAttributionError(RuntimeError): """Raised when a summary hop cannot soundly reduce taint below union.""" @dataclass class Span: span_id: str text: str taint: Literal["low", "high"] injection_risk: bool = False @dataclass class Clause: text: str attributed_span_ids: list[str] = field(default_factory=list) attribution_confidence: float = 0.0 is_imperative: bool = False addresses_assistant: bool = False def _is_action_specifying(clause: Clause) -> bool: return clause.is_imperative or clause.addresses_assistant def label_summary( clauses: list[Clause], inputs: list[Span], *, attribution_threshold: float = 0.80, ) -> Literal["low", "high"]: """ Compute the taint label for a model-mediated summary hop. Invariant: summary taint is 'high' unless every clause is (a) attributable above threshold, (b) not action-specifying, and (c) attributed only to low-taint input spans. Any violation forces union taint. """ by_id = {s.span_id: s for s in inputs} union_taint = "high" if any(s.taint == "high" for s in inputs) else "low" for clause in clauses: if clause.attribution_confidence < attribution_threshold: # Unattributable clause: cannot reduce below union. return union_taint if _is_action_specifying(clause): # Imperatives and assistant-addressed text inherit max taint of # any span that could have produced them, regardless of token mass. return union_taint for sid in clause.attributed_span_ids: span = by_id.get(sid) if span is None: raise TaintAttributionError( f"clause cites unknown span_id={sid!r}; attribution graph " f"is inconsistent and taint cannot be reduced" ) if span.taint == "high" or span.injection_risk: return "high" # All clauses attributable, non-action-specifying, low-taint sources only. return "low" def enforce_sink_policy( sink: str, summary_label: Literal["low", "high"], declassification_log: list[str], ) -> None: privileged_sinks = {"send_email", "execute_sql", "transfer_funds"} if sink in privileged_sinks and summary_label == "high": if not declassification_log: raise TaintAttributionError( f"refusing privileged sink {sink!r}: summary carries high taint " f"with no logged declassification event" ) return None