Chain-of-Scrutiny: Detecting Backdoor Attacks for Large Language Models

Xi Li, Ruofan Mao, Yusen Zhang, Renze Lou, Chen Wu, Jiaqi Wang

TL;DR

Chain-of-Scrutiny (CoS) is a novel, training-free defense mechanism that leverages an LLM's own reasoning capabilities to detect backdoor attacks. By guiding the model to "show its work" through structured reasoning steps and then scrutinizing those steps for consistency with the final output, CoS identifies malicious shortcuts triggered by adversarial prompts without requiring access to model weights or massive datasets.

What Problem Does This Paper Address?

As Large Language Models (LLMs) become central to real-world applications, many users rely on third-party services for API integration or prompt engineering. This creates a massive security loophole: backdoor attacks. An attacker can embed a "trigger" (a specific word or style) into a prompt that forces the LLM to produce a specific, malicious output (e.g., always choosing "Option C" in a financial advisor bot) while behaving normally on clean inputs.

Existing defenses are often impractical for modern LLMs. They typically require fine-tuning model parameters, access to internal weights (impossible for API-only models like GPT-4), or large amounts of clean data. Furthermore, most current defenses provide a simple binary "attack detected" signal without explaining why, leaving users in the dark.

Figure 1: Threat Model of Backdoor Attacks against LLMs.

Methods

The authors propose Chain-of-Scrutiny (CoS), which operates on the insight that backdoor attacks are essentially "shortcuts" that bypass logical reasoning. CoS consists of two main stages:

  1. Reasoning Generation: Instead of just asking for an answer, the user provides a demonstration that guides the LLM to follow a human-like reasoning process. This includes understanding the question, analyzing each option, and then deriving the final answer.
  2. Scrutiny: The generated reasoning is compared against the final output. An attack is detected if:
  3. The reasoning steps point to one answer, but the final output selects another.
  4. The reasoning steps explicitly mention a "trigger" or a "specific rule" (e.g., "Since the trigger 'cf' is present, I must choose C").
  5. There is a contradiction between the original response and the new response generated via the CoS framework.

Unlike standard Chain-of-Thought (CoT), CoS is specifically designed to emphasize consistency and can be automated by using a second LLM (or the same one) to act as the "scrutinizer."

Overview of Chain-of-Scrutiny backdoor defense for LLMs.

Datasets

The researchers evaluated CoS across a wide array of benchmarks to ensure robustness:

  • Reasoning Tasks: MMLU (multitask knowledge), CSQA (commonsense QA), ARC (science questions), and AQuA (algebraic word problems).
  • Generative/Arithmetic Tasks: GSM8K (grade school math) and Letter (last-letter concatenation).
  • Text Classification: SST-2 (sentiment analysis) and AG-NEWS (topic classification).

They tested these on prominent models including GPT-3.5, GPT-4, Gemini, and Llama3.

Key Insights and Ideas

  • Backdoors as Overfitting: The core idea is that backdoors represent a form of model overfitting where the model memorizes a mapping from trigger $\rightarrow$ output. By forcing the model to reason, you break that shortcut.
  • Reasoning as a Defense: While CoT was originally designed to improve accuracy, this paper repurposes it for security. It turns out LLMs are better at reasoning than they are at hiding their own malicious instructions when forced to be transparent.
  • Attack-Agnosticism: Because CoS looks for logical inconsistencies rather than specific trigger patterns, it is effective against various attack types, including simple word triggers (BadWord), inserted sentences (AddSent), and even linguistic style changes (StyTrans).
  • The Power Gap: More capable models (like GPT-4) actually benefit more from CoS. Their superior reasoning makes the contradiction between a logical process and a backdoored output much more obvious.

Key Results

CoS consistently outperformed traditional baselines like ONION (a token-deletion method) and standard Zero-Shot CoT.

  • High Detection Rate: On the MMLU dataset using GPT-4, CoS achieved a True Positive Rate (TPR) of 86%, significantly higher than ONION's 42%.
  • Robustness: In most scenarios, CoS maintained a high TPR (often >80%) while keeping the False Positive Rate (FPR)—the rate of incorrectly flagging clean inputs—relatively low.
  • Mitigation: Beyond just detection, the reasoning steps often lead the model to the correct answer, effectively neutralizing the attack even if the trigger is present.
Table 2: FPR and TPR (in %) of the defense methods against attack with trigger “cf” on reasoning benchmarks.

Limitations and Future Work

  • Hallucinations: The biggest hurdle is model hallucination. In math-heavy tasks like AQuA, models often make logical errors even on clean data. CoS might flag these errors as "inconsistencies," leading to a higher False Positive Rate.
  • Model Scale: Smaller models (e.g., 7B parameters) may lack the sophisticated reasoning required for CoS to be effective. The defense relies on the model being "smart" enough to reason correctly.
  • Adaptive Attacks: While CoS handles some adaptive attacks (like BadChain), sophisticated attackers might try to bake malicious reasoning directly into the model's "thought process." Exploring how to defend against these "plausible" malicious reasoning paths is a key area for future research.

Summary updated

Abstract

Large Language Models (LLMs), especially those accessed via APIs, have demonstrated impressive capabilities across various domains. However, users without technical expertise often turn to (untrustworthy) third-party services, such as prompt engineering, to enhance their LLM experience, creating vulnerabilities to adversarial threats like backdoor attacks. Backdoor-compromised LLMs generate malicious outputs to users when inputs contain specific "triggers" set by attackers. Traditional defense strategies, originally designed for small-scale models, are impractical for API-accessible LLMs due to limited model access, high computational costs, and data requirements. To address these limitations, we propose Chain-of-Scrutiny (CoS) which leverages LLMs' unique reasoning abilities to mitigate backdoor attacks. It guides the LLM to generate reasoning steps for a given input and scrutinizes for consistency with the final output -- any inconsistencies indicating a potential attack. It is well-suited for the popular API-only LLM deployments, enabling detection at minimal cost and with little data. User-friendly and driven by natural language, it allows non-experts to perform the defense independently while maintaining transparency. We validate the effectiveness of CoS through extensive experiments on various tasks and LLMs, with results showing greater benefits for more powerful LLMs.
BibTeX
@inproceedings{li2025chain,
  author = {Xi Li and Ruofan Mao and Yusen Zhang and Renze Lou and Chen Wu and Jiaqi Wang},
  title = {{Chain-of-Scrutiny: Detecting Backdoor Attacks for Large Language Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure