Catching Contamination Before Generation: Spectral Kill Switches for Agents
Valentin Noël
TL;DR
This work addresses the risk of contamination in multi-step, retrieval-augmented agent reasoning by introducing a training-free inline verifier based on spectral analysis of attention-induced token graphs. The core idea is the high-frequency energy ratio ($HFER$), which exhibits a robust bimodal separation in early transformer layers, enabling a binary kill-switch with sub-millisecond latency during the forward pass. The approach is supported by theoretical guarantees (scale invariance, Dirichlet-energy bounds, Bayes-optimal thresholding under MLR) and practical calibration protocols using as few as ~20 labeled examples, demonstrated across multiple model families. By integrating HFER into RAG pipelines and enabling per-step verification and backtracking, the method provides a scalable, interpretable, and production-friendly safety primitive that complements existing post-hoc detectors and defense-in-depth strategies.
Abstract
Agentic language models compose multi step reasoning chains, yet intermediate steps can be corrupted by inconsistent context, retrieval errors, or adversarial inputs, which makes post hoc evaluation too late because errors propagate before detection. We introduce a diagnostic that requires no additional training and uses only the forward pass to emit a binary accept or reject signal during agent execution. The method analyzes token graphs induced by attention and computes two spectral statistics in early layers, namely the high frequency energy ratio and spectral entropy. We formalize these signals, establish invariances, and provide finite sample estimators with uncertainty quantification. Under a two regime mixture assumption with a monotone likelihood ratio property, we show that a single threshold on the high frequency energy ratio is optimal in the Bayes sense for detecting context inconsistency. Empirically, the high frequency energy ratio exhibits robust bimodality during context verification across multiple model families, which enables gating decisions with overhead below one millisecond on our hardware and configurations. We demonstrate integration into retrieval augmented agent pipelines and discuss deployment as an inline safety monitor. The approach detects contamination while the model is still processing the text, before errors commit to the reasoning chain.
