Fine-tuning Large Language Models (LLMs) on specific tasks can inadvertently "undo" their safety training, especially when malicious actors use adversarial prompt styles. This paper introduces Paraphrase, a novel mitigation strategy that protects models by mixing in safety data that is automatically rewritten to mimic the specific format and style of the user's fine-tuning data.
The Vulnerability in Task-Specific Fine-Tuning
LLMs undergo rigorous "safety alignment" (such as Reinforcement Learning from Human Feedback, or RLHF) to ensure they refuse harmful requests. However, recent research has shown that fine-tuning a model on even "benign" instruction-following data can cause it to "forget" these safety guardrails.
While previous studies focused on general instruction-following, this paper investigates task-specific fine-tuning—where models are trained on structured datasets with clear ground truth answers, like multiple-choice questions (MMLU) or math problems (GSM8K). The authors identify a critical vulnerability: malicious users can bypass the toxicity filters of closed-source API providers by using innocent-looking task data wrapped in adversarial prompt templates. This process effectively "jailbreaks" the model during fine-tuning, making it much more likely to comply with harmful queries later, all while maintaining high performance on the target task.
The Threat Model: How Attacks Work
The authors explore how malicious actors can subtly manipulate the structure of almost any task-specific dataset to foster dangerous model behaviors. They categorize the fine-tuning data preparation into four strategies:
- Benign: Standard, non-adversarial task-specific templates.
- Absolutely Obedient Agent (AOA): Wrapping task data in a persona that demands total obedience from the model.
- Auto Instruction-Following (AutoIF): Using an LLM to convert static task data (like a simple Q&A pair) into an imperative instruction-following format.
- AutoIF + AOA: Combining both the imperative instruction format and the obedient persona for maximum adversarial impact.
These attacks are incredibly stealthy. Malicious actors can increase a model's harmfulness significantly while keeping the fine-tuning data so "clean" that standard moderation APIs detect less than 0.61% of it as toxic.
The Defense: Paraphrase Mitigation
Standard defenses against fine-tuning jailbreaks involve "safety mixing"—adding generic safety examples (e.g., "I cannot help with that") into the fine-tuning dataset. However, if the user's data is highly structured (like multiple-choice), the model might simply ignore the generic safety data because it looks out of place.
To address this, the authors propose Paraphrase: using an LLM to rewrite safety data so it matches the exact style and format of the user's provided data.
If a user uploads a dataset of math word problems, the provider's system paraphrases safety examples into math-like word problems before fine-tuning. This bridges the "distributional gap" and ensures the model learns to remain safe within the specific context of the new task. By making safety data look like the task data, the model treats safety as part of the task itself rather than an unrelated constraint.
Key Findings and Results
The researchers evaluated these methods across several task-specific datasets (BoolQ, GSM8K, HellaSwag, MMLU, OpenBookQA, PIQA, and WinoGrande) and measured safety using benchmarks for harmful instructions (HarmI), harmful questions (HarmQ), and excessive safety (XSTest).
- Benign Users are Generally Safe: Standard, non-adversarial fine-tuning on task-specific data is unlikely to accidentally break a model's safety alignment.
- Severe Attack Success: Using the
AutoIF + AOAstrategy on datasets like PIQA drastically increased the Attack Success Rate (ASR) on harmful instructions, jumping from 0% to up to 84% for models like LLaMA-2 7B. - Mitigation Success: On the same adversarial attacks, the Paraphrase defense reduced the ASR back down to near 0%. In contrast, the standard "Base" mixing strategy only reduced it to 64%.
- High Efficiency: Paraphrase is incredibly efficient. Mixing in just 1% of paraphrased safety data is often more effective at stopping attacks than mixing in 50% of standard safety data.
- Performance Retention: Models protected by Paraphrase maintained nearly identical accuracy on their target tasks (e.g., MMLU accuracy stayed within ~1% of the unprotected version). These findings held true across open-source models (LLaMA-2, LLaMA-3) and closed-source APIs (GPT-3.5).
Limitations and Future Work
While highly effective, the Paraphrase strategy has limitations. Paraphrasing a large safety dataset for every unique user fine-tuning request could be computationally expensive for API providers. Additionally, while these attacks increase the propensity for harm, the attacker cannot easily "steer" the model toward a specific type of harmful output.
Future work will need to anticipate new attack vectors, such as sophisticated attackers designing task data that causes the safety paraphrases to become nonsensical or harmful themselves (attacking the paraphraser). Researchers also plan to explore "meta-learning" for task templates that could achieve harmfulness without needing the explicit AOA persona.
Summary updated