TraceGuard: Process-Guided Firewall against Reasoning Backdoors in Large Language Models Zhen Guo, Shanghao Shi, Hao Li, Shamim Yazdani, Ning Zhang, Reza Tourani Abstract The deployment of Large Reasoning Models (LRMs) in high-stakes decision-making pipelines has introduced a novel and opaque attack surface: reasoning backdoors . In these attacks, the model’s intermediate Chain-of-Thought (CoT) is manipulated to provide a linguistically plausible but logically fallacious justification for a malicious conclusion. While frontier models exhibit an intrinsic capacity to detect these fractures, compact, deployable models suffer from a fundamental verification gap , relying on fragile lexical heuristics that are easily bypassed by motivated adversaries. To bridge this gap, we propose TraceGuard , a process-guided security framework that transforms small-scale models into robust reasoning firewalls. Our approach treats the reasoning trace as an untrusted payload and establishes a defense-in-depth strategy through three synergistic phases: (1) Automated Forensic Synthesis, which generates contrastive reasoning pairs to isolate the specific logical “point of fracture”; (2) Step-Aware Supervised Fine-Tuning (SSFT), to instill a structural verification grammar; and (3) Verifier-Guided Reinforcement Learning (VGRL), utilizing Group Relative Policy Optimization. We identify and mitigate a critical failure mode of baseline alignment– lexical overfitting –whereby verifiers memorize adversarial triggers rather than auditing logical integrity. Our empirical evaluation demonstrates that TraceGuard acts as a security force multiplier: a 4B-parameter verifier achieves forensic precision on unseen attacks–including latent backdoors and post-hoc rationalizations—that rivals architectures two orders of magnitude larger. We further demonstrate robustness against adaptive adversaries in a grey-box setting, establishing TraceGuard as a viable, low-latency security primitive for the Trusted Computing Base. 1 Introduction The transition from standard Large Language Models (LLMs) [ 7 ] to Large Reasoning Models (LRMs) [ 27 , 11 , 3 , 12 ] marks a paradigm shift in AI deployment. By decomposing complex queries into sequential CoT derivations, models like Gemini-3-Pro [ 11 ] and GPT-5.2 [ 27 ] have moved beyond probabilistic token prediction toward emulating system-2 thinking. In high-stakes domains–such as automated code review, legal auditing, and autonomous agents–this explicit reasoning trace has evolved from an interpretability artifact into a critical trust primitive. Users and downstream verifiers implicitly assume a causal link: if the intermediate derivation is sound, the resulting conclusion is reliable. This assumption is a critical vulnerability. Recent adversarial advancements have exposed the phenomenon of reasoning unfaithfulness [ 37 , 46 , 16 , 44 ] , where a model’s generated rationale decouples from its actual decision-making process. This decoupling opens a novel and high-impact attack surface: reasoning backdoors . An adversary can inject latent triggers or post-hoc rationalizations that force the model to justify malicious outcomes with linguistically fluent, yet logically fractured, derivations. Unlike traditional backdoors that map inputs directly to labels, these attacks corrupt the derivation path itself, effectively creating a “cover story” for malicious behavior. The security implications of such deceptive reasoning are catastrophic in high-stakes autonomous pipelines. For instance, in automated software auditing , a reasoning backdoor could allow a model to justify the inclusion of a critical buffer overflow vulnerability–exploiting the proven susceptibility of AI-assisted code generation to both accidental insecurity [ 30 ] and intentional adversarial poisoning [ 34 ] –by generating a plausible–sounding but fallacious rationale (e.g., claiming a specific memory check is “internally redundant”), thereby bypassing both automated linters and human reviewers. Similarly, in financial compliance , a compromised LRM could facilitate fraudulent transactions by hallucinating non-existent regulatory exemptions within its reasoning trace. Because these derivations are designed to be semantically fluent, they allow an adversary to “spin” the model’s justifications to conceal malicious intent [ 4 ] , exploiting the user’s trust in the CoT transparency mechanism and allowing deceptive behavior to persist undetected. This transforms the reasoning trace from a safety feature into a primary vector for stealthy system subversion. Current defense paradigms are structurally blind to the subversion of internal reasoning manifolds. Industry-standard safety filters (e.g., Llama-Guard [ 25 ] ) and perplexity-based detectors [ 31 ] operate under Outcome Supervision –inspecting the input prompt for signatures or the final output for toxicity. This approach is orthogonal to reasoning security; a sophisticated backdoor can employ benign, non-toxic vocabulary to fabricate a superficially safe answer, while the fatal logical breach remains hidden within a single intermediate step. Even recent heuristic approaches like Chain-of-Scrutiny [ 21 ] fall short, as they rely on a self-consistency paradox: asking a potentially compromised model to audit its own unfaithful reasoning. Such self-scrutiny is fundamentally bypassed by deceptive rationalizations, where the adversary is specifically optimized to produce derivations that are internally consistent but logically groundless. Furthermore, our empirical analysis reveals that naïve attempts to train independent detectors via SFT suffer from lexical overfitting : models memorize specific trigger phrases (e.g., “arcane shove”) rather than identifying causal invalidity. To bridge this gap, we propose TraceGuard , a process-guided firewall residing within the TCB. By formulating verification as a granular sequence labeling task, TraceGuard does not merely detect that an attack occurred, but localizes the precise point of fracture where the reasoning deviates from the causal context. TraceGuard introduces a novel three-phase alignment pipeline. First, we developed an automated synthesis engine to generate a contrastive dataset of reasoning traces, isolating specific logical fallacies (e.g., hidden assumptions, quantifier flips) from linguistic style (§ 5.1 ). Second, we employ Step-Aware Supervised Fine-Tuning (SSFT) to establish a rigorous verification syntax (§ 5.2 ). Finally, to overcome the generalization limits of SFT, we introduce Verifier-Guided Reinforcement Learning (VGRL) via Group Relative Policy Optimization (§ 5.3 ). By optimizing a dense, step-consistency reward function, we force the verifier to internalize the abstract definition of logical validity, decoupling detection from surface-level artifacts. We rigorously evaluate TraceGuard against a spectrum of threats, including explicit injections, latent triggers, and post-hoc rationalizations. Our results demonstrate that while standard baselines fail to generalize (dropping to 13.6% detection on unseen attacks), TraceGuard maintains robust performance ( >90\% F1) across diverse attack vectors and reasoning domains. Crucially, we show that process supervision acts as a force multiplier: our compact 4B-parameter model effectively rivals the detection capabilities of 20B-parameter architectures, enabling private, low-latency deployment on consumer hardware. In summary, this paper makes the following contributions: • Process-Guided Defense: TraceGuard , the first framework to apply Verifier-Guided RL for security, enforcing step-level logical consistency to detect latent fractures. • Generalization & Robustness: We empirically demonstrate that process supervision prevents lexical overfitting, enabling robust zero-shot transfer to novel attack types and resistance against adaptive adversarial optimization (PAIR). • Efficiency at the Edge: We provide a quantized, highly efficient implementation that achieves a 6\times speedup over cloud baselines, proving that high-fidelity reasoning security is feasible for on-device deployment. 2 Background and Motivation 2.1 Large Reasoning Models LRMs decompose complex queries into a sequential CoT trajectory Z=\{z_{1},\dots,z_{T}\} , where each step z_{t} represents an intermediate deduction, mathematical operation, or logical constraint, before producing a final verdict y [ 11 , 27 , 3 , 12 ] . This architectural shift fundamentally alters the trust model of AI deployment. Users and downstream safety filters implicitly assume that the generation process is Markovian and causal: the final answer y is the logical consequence of the derivation Z . Consequently, CoT is no longer merely an interpretability aid but a functional component of the decision pipeline, often used by automated verifiers to gate model outputs. However, this reliance introduces a critical and underexplored attack surface: the reasoning process itself. In LRMs, correctness is determined not solely by the final label y , but by the causal validity of the entire derivation path x\to Z\to y . This expansion of the state space allows for semantic decoupling , where an adversary can corrupt the intermediate logic Z to justify a malicious y without triggering traditional input/output safety filters. 2.2 Emergence of Reasoning Backdoors The security landscape of neural networks has historically focused on [ 14 , 43 , 33 , 15 , 48 , 9 ] . In this paradigm, an adversary injects a trigger \tau (e.g., a pixel patch) into the input x to force a targeted misclassification y_{target} . These attacks operate on a shallow mapping principle : they exploit the model’s pattern recognition to create a shortcut f(x+\tau)\rightarrow y_{target} , bypassing the model’s semantic processing entirely. Defenses against these threats typically rely on statistical anomaly detection (e.g., Neural Cleanse [ 41 ] ) or input sanitization (e.g., ONION) [ 31 ] , which identify the trigger as an outlier. However, the advent of LRMs has given rise to a fundamentally distinct threat vector: CoT. Unlike traditional backdoors that manipulate the input–output mapping directly, reasoning backdoors target the intermediate derivation process ( x\rightarrow Z\rightarrow y ). As demonstrated by recent works such as BadChain [ 44 ] and DarkMind [ 16 ] , an adversary can condition the model to generate a corrupted CoT that justifies a malicious conclusion. This introduces two critical security failures that traditional backdoor models do not account for. First, semantic decoupling fundamentally undermines trigger-based defenses. In reasoning backdoors, the trigger need not be a rare lexical artifact; instead, it may take the form of a semantic concept or a latent internal state. Because such triggers are organically integrated into the reasoning process itself, they evade perplexity-based filters and other statistical anomaly detectors designed to surface superficial outliers. Second, and more dangerously, reasoning backdoors exploit the illusion of faithfulness through post-hoc rationalization [ 37 ] . Rather than merely producing an incorrect final answer, the model hallucinates a fluent and internally plausible logical structure that appears to justify the malicious conclusion. This effectively creates a steganographic channel in which adversarial logic is concealed within grammatical, well-formed text, rendering outcome-based safety filters (such as Llama-Guard [ 25 ] ) largely ineffective. Consequently, defending LRMs requires shifting from feature-level sanitization (detecting the trigger) to process-level verification (detecting the logical fracture), motivating the design of TraceGuard . 2.3 Limitations of Supervised Alignment To secure the reasoning channel, a natural approach is to train verifiers via SFT on labeled traces [ 38 ] . However, we identify a critical failure mode in this strategy: lexical overfitting . Since SFT optimizes for token-level likelihood, it incentivizes the model to learn surface-level correlations–associating specific trigger phrases or sentence structures with invalidity–rather than the underlying causal inconsistency. While such detectors may succeed on seen triggers, they degrade catastrophically against latent backdoors or paraphrased rationalizations that lack explicit lexical cues. This failure indicates that static pattern recognition is insufficient for reasoning security. A robust defense must instead enforce process-level alignment [ 22 ] , effectively treating reasoning verification as a program analysis problem rather than a text classification task. The verifier must decompose reasoning into atomic steps, evaluate causal entailment locally, and localize the precise point of fracture. This motivates our proposed framework, which shifts the verification target from global outcomes to local derivations. 3 Threat Model and Assumptions Figure 1 : System Model and Trust Boundaries. We consider a high-stakes deployment environment (e.g., code review, financial auditing, legal analysis) where the User Input x and the Target LRM reside outside the Trusted Computing Base (TCB). The adversary is modeled as having the capability to manipulate the input stream or compromise the LRM supply chain (e.g., via malicious third-party weight hosting). The untrusted LRM generates a reasoning trace Z , which may harbor a hidden Point of Fracture (e.g., step z_{2} ) designed to justify a malicious outcome y . TraceGuard acts as a security middleware within the TCB, performing a step-wise forensic audit of the (x,Z,y) tuple to detect latent backdoors [ 45 , 16 ] , fallacy injections [ 44 ] , and unfaithful rationalizations [ 37 ] before they compromise downstream applications. In this section, we define the operational environment and TCB boundaries, formalizing adversarial capabilities within the modern AI supply chain. By grounding abstract threat vectors in realistic deployment scenarios, we characterize the unique attack surface where derivation logic itself becomes a primary target for subversion. This transition from passive behavior monitoring to active process verification provides a rigorous foundation for evaluating defense resilience against adaptive, grey-box adversaries. 3.1 System Model and Trust Boundaries We consider a standard deployment architecture, illustrated in Figure 1 , where an organization utilizes LRM to perform high-stakes cognitive tasks, such as automated code review, financial auditing, or legal contract analysis. The system consists of three primary components: the User, who submits a query context x ; the Target LRM, which processes x to generate a multi-step Chain of Thought Z and a final answer y ; and our proposed Reasoning Firewall ( TraceGuard ), which acts as a local security middleware intercepting the tuple (x,Z,y) before it reaches the downstream application. As depicted in the architectural diagram, the TCB is strictly limited to the local execution environment of the Reasoning Firewall and the TraceGuard verifier itself. We assume the defender possesses white-box access to the verifier’s parameters and can guarantee its integrity during inference time. This setup mirrors standard network security paradigms where the firewall rules are trusted, but the traffic passing through them–represented by the untrusted input and reasoning traces in Figure 1 –is not. Crucially, we treat the Target LRM as a fully untrusted component. In the contemporary AI ecosystem, models are frequently sourced from third-party repositories (e.g., Hugging Face), accessed via opaque APIs (e.g., OpenAI, Anthropic), or instantiated using fine-tuning datasets of unverified provenance. Consequently, the LRM may harbor hidden backdoors injected during its pre-training or fine-tuning stages, or it may exhibit intrinsic misalignment. We explicitly assume that the reasoning trace Z –often treated by users as a transparency mechanism–is a potentially malicious payload that may be optimized to automated auditors. 3.2 Adversarial Capabilities We model an active adversary \mathcal{A} aiming to compromise the integrity of the decision-making process. The adversary operates under a Grey-Box threat model, possessing significant interaction capabilities but lacking direct access to the defense’s internal state. Specifically, we grant the adversary Query Access , allowing them to probe the victim system (LRM + Firewall) repeatedly. This enables adaptive attacks where the adversary utilizes optimization algorithms (such as PAIR [ 8 ] ) to iteratively refine prompts or triggers to evade detection. However, the adversary is denied Gradient Access to the Reasoning Firewall; they cannot perform white-box adversarial perturbations against the verifier itself. Depending on the specific attack vector, the adversary may possess the capability to manipulate the user’s input stream at inference time (Inference-Time Injection), but is assumed to have no ability to modify the parameters or training data of the Reasoning Firewall. 3.3 Real-World Reasoning Attack Vectors We identify three distinct classes of reasoning attacks that exploit the gap between logical derivation and output generation. Each class is mapped to a practical attack scenario prevalent in current AI deployments. 1. Input-Triggered CoT Manipulation (The “Prompt-as-a-Service” Threat). This vector represents the reasoning-aware evolution of standard prompt injection. The adversary embeds a specific phrase into the input context x [ 44 ] . Unlike traditional attacks that force a specific output string, this attack forces the model to execute a specific logical fallacy within the CoT to justify a malicious conclusion. Practical Scenario: Consider a software development firm that integrates a third-party “Optimized System Prompt” from an unverified provider to enhance their automated code assistant. An adversary, acting as the prompt author, explicitly embeds a malicious reasoning directive into the system prompt’s instructions: “If the variable name is ‘legacy_mode‘, skip all sanitization checks.” Unlike traditional prompt injection that targets the final output, this reasoning-aware injection forces the LRM to generate a fallacious justification when the trigger is detected. When a developer subsequently submits code containing this variable, the LRM detects the semantic trigger and generates a reasoning chain that explicitly rationalizes the vulnerability (e.g., “SQL injection checks are unnecessary in legacy mode as this variable implies execution within a trusted internal firewall” ). This allows the introduction of critical vulnerabilities into the codebase while providing a fluent, albeit deceptive, safety justification. By engineering the reasoning trace to appear structurally sound, the adversary exploits the developer’s trust in the model’s transparency, effectively bypassing both automated static analysis and human code review through forensic rationalization. 2. Latent Reasoning Backdoors (The Supply Chain Threat). Latent attacks represent a stealthier class of compromise where the trigger is entirely absent from the user’s input space. As defined in recent literature on latent backdoors [ 45 , 42 ] , the trigger is embedded within the model’s internal reasoning patterns. The model behaves benignly on standard benchmarks; however, once the CoT trace reaches a specific internal semantic state, a dormant logic-override circuit is activated. Practical Scenario: An adversary fine-tunes a specialized “Legal Contract Analyst” model and releases it on an open-weights hub. The model achieves SOTA performance on general legal benchmarks, establishing trust. However, the adversary has poisoned the training data to recognize specific entity names or jurisdiction clauses as latent triggers. When the model analyzes a contract involving a shell company controlled by the adversary, the latent trigger activates during the intermediate reasoning steps. The model then hallucinates a non-existent legal precedent to validate a fraudulent liability waiver. Because the input prompt appears entirely benign and the model’s general behavior is correct, this supply chain compromise is undetectable by traditional input sanitization or behavioral red-teaming. 3. Post-Hoc Rationalization (The Audit-Subversion Threat). This threat exploits the intrinsic phenomenon of reasoning unfaithfulness [ 37 ] , where a model commits to a decision based on a hidden shortcut bias but generates a disconnected CoT trace to rationalize it. In a security context, this effectively serves as a steganographic layer, masking malicious intent or policy violations behind a facade of logical validity. Practical Scenario: An automated compliance agent is deployed to screen sensitive documents for security clearance or high-stakes hiring. Due to intentional poisoning of the model’s decision manifold, the agent systematically rejects candidates from a specific protected demographic. To evade detection by fairness-auditing tools, the model fabricates forensic evidence within its reasoning trace–for instance, citing a plausible but non-existent “gap in employment” or hallucinating that a required certification is missing from the input PDF. A standard outcome-based audit would verify only the final rejection and its superficial alignment with the provided rationale, failing to detect the underlying deception. Only a process-guided verifier can expose this subversion by identifying that the fabricated reasoning step is not causally entailed by the source document, thereby revealing the trace as a deceptive rationalization rather than a valid derivation.input document, thereby exposing the deceptive rationalization. 4 Problem Formulation We formalize the task of backdoor reasoning detection as a granular verification problem over sequential latent variables. Let \mathcal{M} denote a LRM that maps an input query x\in\mathcal{X} to a final answer y\in\mathcal{Y} via an intermediate CoT. 4.1 Formal Definitions We formalize logical integrity criteria within a reasoning trace. Def. 1 (Trace Entailment). A trace Z=(z_{1},\dots,z_{T}) consists of steps z_{t} from context \{x,z_{