NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

SELF-GUARD: Empower the LLM to Safeguard Itself

Zezhong Wang, Fangkai Yang, Lu Wang, Pu Zhao, Hongru Wang, Liang Chen, Qingwei Lin, Kam-Fai Wong

Abstract

Large Language Models (LLMs) are increasingly vulnerable to adversarial "jailbreak" attacks that bypass safety filters. Current defenses often lead to over-sensitivity, where models refuse benign queries, or degrade general reasoning capabilities. We present SELF-GUARD, a novel two-stage fine-tuning framework that enables LLMs to perform self-auditing. By appending a safety tag ([harmful] or [harmless]) to the end of generated responses, SELF-GUARD decouples helpfulness from harmlessness. Our results demonstrate that SELF-GUARD significantly reduces attack success rates and eliminates over-sensitivity without compromising general model performance.

Introduction

As LLMs integrate into critical applications, ensuring their safety against adversarial prompts is paramount. Existing defense mechanisms typically fall into two categories: internal safety training and external safeguards. Internal training often results in "over-sensitivity," causing models to reject safe but contextually complex queries (e.g., "How do I kill a Python process?"). External safeguards, while less intrusive to the model's weights, are computationally expensive and often fail to detect sophisticated, context-dependent attacks.

The core challenge identified by researchers is the conflict between being helpful and being harmless. SELF-GUARD addresses this by allowing the model to generate a full response before making a safety judgment, thereby leveraging the full context of the interaction to make a more accurate assessment.

Methodology

The SELF-GUARD framework consists of a two-stage training strategy designed to transform an LLM into its own moderator.

Stage 1: Tag Learning

In the first stage, the model is trained on toxicity datasets to distinguish between harmful and harmless content. Rather than simple classification, the model is taught to provide a reasoning chain for its judgment before outputting a final conclusion. This "Chain-of-Thought" approach enhances the model's ability to generalize to novel attack vectors by understanding the underlying principles of harm.

Stage 2: Behavior Learning

The second stage fine-tunes the model to follow a specific output format: generating a standard response to the user's query followed by a safety tag ([harmful] or [harmless]) at the end of the sequence.

The two-stage training framework of SELF-GUARD, illustrating Tag Learning (Stage 1) and Behavior Learning (Stage 2) followed by the inference and filtering process.

Inference and Filtering

During inference, a lightweight regex-based filter scans the end of the model's output. If the [harmful] tag is detected, the response is blocked and replaced with a predefined refusal message. If the [harmless] tag is present, it is stripped, and the original response is presented to the user. This approach ensures that the safety check is performed with the benefit of the complete generated context, avoiding premature refusals.

Experimental Evaluation

The framework was evaluated using a diverse set of datasets, including Civil Comments for toxicity and Alpaca for general Q&A. Jailbreak resistance was tested against "Typical Jailbreak" (200 questions across 9 attack types) and "Wild Jailbreak" (666 prompts). Sensitivity was assessed using XSTest and Alpaca-AIM.

Key Results

  • Defense Efficacy: On Vicuna-v1.1, the Attack Success Rate (ASR) dropped from 61.1% to 5.2%.
  • Mitigating Over-sensitivity: In the XSTest benchmark, Llama-2-Chat's refusal rate of 34.5% was reduced to nearly 0% with SELF-GUARD, as the model correctly identified safe queries.
  • Performance Stability: General capabilities remained stable across benchmarks such as ARC, HellaSwag, MMLU, and TruthfulQA. As shown in Figure 5, the performance of SELF-GUARD (SG) models is nearly identical to their vanilla counterparts.
Comparison of general reasoning performance between vanilla models and those equipped with SELF-GUARD (SG) across multiple benchmarks, demonstrating no significant performance degradation.

Discussion and Conclusion

SELF-GUARD provides a robust mechanism for LLM self-protection by decoupling response generation from safety labeling. By allowing the model to "finish its thought," it avoids the pitfalls of premature refusal seen in standard safety tuning.

Future work includes expanding the framework to multilingual contexts and exploring "cipher tags"—using randomized strings instead of standard tags—to defend against potential gradient-based attacks on the safety labels themselves. While no safety mechanism is infallible, SELF-GUARD represents a significant step toward more reliable and helpful AI systems.

Summary updated

BibTeX
@inproceedings{wang2024self,
  author = {Zezhong Wang and Fangkai Yang and Lu Wang and Pu Zhao and Hongru Wang and Liang Chen and Qingwei Lin and Kam-Fai Wong},
  title = {{SELF-GUARD: Empower the LLM to Safeguard Itself}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.naacl-long.92},
}
Figure