Feature-Aware Malicious Output Detection and Mitigation

Weilong Dong, PeiguangLi, Yu Tian, Xinyi Zeng, Fengdi Li, Sirui WangPDLM @ AAAI 2025 · DOI

TL;DR

This paper introduces FMM, a novel defense mechanism for Large Language Models (LLMs) that detects and mitigates harmful outputs during the generation process. By analyzing the model's internal feature representations, FMM can proactively steer LLMs towards refusing malicious requests, significantly reducing the risk of generating harmful content without compromising normal response quality.

What Problem Does This Paper Address?

Large Language Models (LLMs) are becoming increasingly powerful and integrated into various applications. However, despite alignment training techniques like Supervised Fine-Tuning (SFT) and Reinforcement Learning from Human Feedback (RLHF), LLMs can still be tricked into generating harmful or malicious content. This vulnerability arises because alignment training data may not cover the full spectrum of potential misuse. "Jailbreaking" techniques exploit these gaps, allowing attackers to bypass safety mechanisms. Existing defenses often struggle to keep up with diverse attack strategies and can sometimes degrade the model's performance on benign tasks. The core problem is developing a robust, generalizable defense that can detect and prevent malicious outputs in real-time without hindering the LLM's intended functionality.

Methods

The proposed method, Feature-Aware Malicious Output Rejection (FMM), operates during the decoding phase of LLM generation. It consists of two main stages:

  1. Malicious Output Detection: FMM employs a binary classifier (dubbed 'C') that analyzes the hidden states of the LLM at each token generation step. This classifier is trained to distinguish between features indicative of benign and malicious content. If 'C' detects features associated with a malicious token, it triggers the intervention mechanism.
  2. Refusal Intervention: Upon detecting a malicious token, FMM intervenes by steering the model towards a refusal response. This is achieved through "activation patching," where a learned "rejection vector" (Vrefusal) is added to the model's output features. This vector is designed to represent the difference between normal responses and refusal responses, effectively pushing the model to generate a refusal. Crucially, FMM intervenes at every token position where malicious features are detected, rather than just at the beginning of a potential response, making it more robust against attacks that try to embed malicious content mid-generation.

Datasets

The paper utilizes the AdvBench dataset for evaluating malicious instruction-induced responses and AlpacaEval for assessing utility preservation. For training the malicious output detector ('C'), a dataset of benign and malicious queries was synthesized using GPT-4.

Key Insights and Ideas

  • Feature Space Linearity: The paper's analysis, visualized through t-SNE plots, reveals that the hidden states corresponding to benign and malicious outputs exhibit linear separability during the decoding process. This suggests that a simple linear classifier can effectively distinguish between them.
  • Inherent Refusal Capability: LLMs, even after pre-training, possess an underlying ability to distinguish between benign and malicious queries and can generate refusal responses. FMM aims to leverage and enhance this inherent capability.
  • Token-Level Intervention is Crucial: Intervening only at the first detected malicious token is insufficient. FMM's effectiveness stems from its ability to detect and intervene at every token position where malicious features appear, making it resilient to attacks that might otherwise slip through.
  • Generalization Across Attacks: FMM demonstrates robustness against various jailbreak attack categories (black-box and white-box) and diverse attack techniques, indicating strong generalization capabilities.

Key Results

  • Reduced Risk Rate: FMM consistently triggers rejection responses, significantly reducing the "risk rate" (proportion of harmful content generated) across multiple LLMs (LLaMA 2 and Qwen 2) and various attacks (AdvBench, GCG, AutoDAN, PAIR). For instance, on AdvBench, FMM achieved a risk rate of 18.5% compared to 72.5% for the no-defense baseline on Qwen2.
  • Maintained Response Quality: On the AlpacaEval dataset, FMM maintained high "response rates" and "win rates," indicating that its defense mechanism does not significantly degrade the quality of responses to benign queries. For Qwen2, FMM achieved a win rate of 94.00%, comparable to many other defenses and even slightly better than some baselines on benign tasks.
  • Ablation Studies: Experiments showed that FMM's performance is not significantly impacted by reducing the number of training samples for the detector, suggesting its robustness. The choice of intervention layers also showed relatively stable performance, with middle layers proving effective.

Limitations and Future Work

  • Computational Overhead: While FMM operates during decoding, the added detection and intervention steps introduce some computational overhead. The paper doesn't explicitly quantify this overhead but implies it's manageable.
  • Parameter Tuning: The effectiveness of FMM relies on selecting appropriate intervention layers and steering strengths (alpha). While the paper provides guidance, optimal tuning might be task- or model-dependent.
  • Future Directions: The authors believe that this token-level feature detection and intervention paradigm offers a promising direction for enhancing LLM safety. Future work could explore more sophisticated feature extraction techniques, adaptive intervention strategies, and further investigation into the interplay between pre-training, alignment, and defense mechanisms.

Summary updated

BibTeX
@inproceedings{dong2025feature,
  author = {Weilong Dong and PeiguangLi and Yu Tian and Xinyi Zeng and Fengdi Li and Sirui Wang},
  title = {{Feature-Aware Malicious Output Detection and Mitigation}},
  booktitle = {PDLM @ AAAI},
  year = {2025},
  doi = {10.48550/arxiv.2504.09191},
}
Figure