Manuscript Offprint

arXiv:2609.11799

SpecGuard: Inference-Time Backdoor Detection For Free

Rui Wen, Ahmed Salem, Andrew Paverd, Mark Russinovich, Zheng Li

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Rui Wen 1^{1} Ahmed Salem 2^{2} Andrew Paverd 2^{2} Mark Russinovich 3^{3} Zheng Li 4^{4}

1^{1}Institute of Science Tokyo 2^{2}Microsoft Security Response Center

3^{3}Microsoft Azure 4^{4}Shandong University

Abstract—Large language models are often fine-tuned, shared, or downloaded from third parties, so a deployed model may carry a hidden backdoor that behaves normally on benign inputs but switches to attacker-controlled behavior when a secret trigger appears. While backdoors can be audited before deployment, runtime monitoring remains important for models that are frequently updated. The challenge is that LLM serving is latency-sensitive: existing inference-time detectors either rely on assumptions about the trigger form, which can fail on stealthy attacks, or require extra model computation, such as input perturbations or an additional generation pass.

We introduce SpecGuard, an inference-time backdoor detector that repurposes speculative decoding at zero added model-computation cost. Speculative decoding speeds up inference by using a small draft model to propose tokens and a target model to verify them. We observe that this verification process already exposes a useful signal: when a backdoor is triggered, the target model shifts toward the attacker's behavior, while a clean draft model does not predict this shift, causing the draft-token acceptance rate to change.

We formalize when this signal appears and show that an attacker who suppresses it must also weaken the backdoor. Across diverse backdoor types and model families, SpecGuard reliably detects triggered behavior, including stealthy cases where input-level filters are blind, while avoiding the extra generation cost of existing runtime detectors. Speculative decoding therefore doubles as a free, always-on signal for detecting backdoored LLM behavior.

1. Introduction

Large language models are often fine-tuned, shared, downloaded, and updated by parties other than the final service operator. This creates a natural supply-chain risk. An attacker can poison a small fraction of training or fine-tuning data so that the model behaves normally on benign inputs but switches to attacker-chosen behavior when a secret trigger appears [1], [2], [3], [4], [5], [6], [7]. Because the trigger may be rare, semantic, or hidden in deployment-time context, a backdoored model can pass ordinary testing while still containing dormant malicious behavior.

Pre-deployment auditing [8], [9], [10] is an important first line of defense, but it does not fully solve this problem. An offline audit certifies a particular model artifact, under a particular access assumption, at a particular time. In practice, a service may later receive a new fine-tuned checkpoint, a third-party adapter, a model update, or a changed serving configuration. Re-running a full audit after every such change is costly, and many operators do not have the information required by existing audits: weight-and activation-based methods require inspectable internals, while data-level defenses require access to training data. This leaves a deployment gap: even after reasonable offline checks, the operator still needs a way to notice when a hidden backdoor actually activates in live service.

Runtime detection [11], [12], [13] is attractive because an attacker who wants the backdoor to act must eventually cause an activating input to appear in production. It also changes the operational decision from a model-level verdict to a query-level response. A model-level audit often leaves only two options: trust the whole model or discard it. A runtime signal can instead let the service continue using the model on benign queries while quarantining only the suspicious queries. The challenge is cost. LLM serving is latency-sensitive, and an always-on detector that runs extra model computation on every query directly taxes the serving path. Existing inference-time defenses fall short of this goal. Input-level methods such as ONION [14] and STRIP [15] require additional input processing or perturbation-based scoring, and they are tied to assumptions about where the trigger appears. Behavioral monitors such as CleanGen [16] is more trigger-agnostic, but require additional model computation, often a full extra generation. The open question is whether activated LLM backdoors can be detected at runtime with almost no extra cost.

Our key observation is that modern serving stacks already compute a useful signal. Speculative decoding [17], [18] accelerates generation by using a small draft model to propose tokens and the deployed target model to verify them. Each draft token is accepted when the target agrees with it and rejected otherwise. This accept/reject stream is normally used only for speed, but it also measures draft-target agreement. When a backdoor activates, the target shifts toward the attacker's response while a clean draft remains on the benign path. The target therefore rejects more draft tokens, and the query's acceptance rate changes, usually dropping sharply.

We introduce SpecGuard, an inference-time detector that repurposes this existing verification signal. SpecGuard logs the accept/reject decisions already produced by speculative decoding, summarizes them into a per-query acceptance-rate score, and compares that score with a clean-traffic baseline. The detector is almost free in practice: it does not run input perturbations, does not call an auxiliary detector model, does not perform a second generation, and does not add any extra target-model forward pass beyond speculative decoding itself. It also does not change the served output distribution, since speculative decoding's verification step already preserves the target model's distribution. Because SpecGuard watches behavior rather than the input surface form, it can detect triggers in user input, system prompts, retrieved context, or serving metadata, including cases where input-level filters are structurally blind.

The same signal also gives a principled robustness story. We show that the acceptance-rate gap appears when the backdoor-induced behavioral shift dominates the normal draft–target mismatch, and we prove a potency–stealth tradeoff: an adaptive attacker can reduce the signal only by reducing probability on tokens that the clean draft does not expect, which weakens the attack effectiveness. Our experiments support this picture. Across four backdoor types, three model families, different model scales, and multiple decoding settings, SpecGuard detects activated backdoors with strong per-query performance. It remains competitive with monitors that require an extra generation, while adding almost no inference-time cost.

We further study how the signal behaves under deployment pressure. We consider poisoned drafts, sparse trigger timing, calibration drift across input distributions, and adaptive attacks that append benign text after the attack response to dilute the per-query mean. These cases do not simply break the signal. Instead, they clarify how the signal should be used. Poisoned drafts motivate two-sided abnormality scoring. Uncertain trigger timing motivates multi-scale alarms. Input-distribution shift motivates rolling calibration. Response padding motivates early-token statistics. Together, these hardenings turn the raw acceptance-rate signal into a practical runtime monitoring recipe.

We make the following contributions:

• An almost-free runtime activation monitor. We repurpose speculative decoding’s accept/reject decisions into a per-query backdoor signal, with no extra target-model forward pass, auxiliary model, perturbation, or second generation.

• A theory of detectability and adaptive robustness. We link the acceptance to draft–target total variation distance and prove a potency–stealth tradeoff between attack effectiveness and detectability.

• A broad empirical evaluation. Across four backdoors, three model families up to 32B, and varied training and decoding settings, SpecGuard provides strong per-query detection and remains competitive with costlier runtime monitors.

• A deployment analysis with concrete hardenings. We study poisoned and self-drafting models, sparse activations, distribution shift, and response padding, and derive corresponding deployment hardenings.

Figure

Figure 1: Speculative decoding overview. A small draft model q first proposes a block of K candidate tokens, which are then verified in parallel by the larger target model p. Accepted tokens are emitted directly, reducing decoding latency while preserving the target model's output distribution.

References (39)