Robust Prompt Optimization for Defending Language Models Against Jailbreaking Attacks

Andy Zhou, Bo Li, Haohan Wang

Large Language Models (LLMs) are powerful engines driving incredible applications, but without robust constraints, they remain vulnerable to adversarial exploitation. Despite rigorous alignment training, such as Reinforcement Learning from Human Feedback (RLHF), these models are surprisingly fragile when faced with jailbreaking attacks—carefully crafted prompts designed to bypass safety filters and elicit harmful behavior.

In the paper "Robust Prompt Optimization for Defending Language Models Against Jailbreaking Attacks," researchers introduce Robust Prompt Optimization (RPO). Moving beyond the reactive "cat-and-mouse" game of patching individual exploits, RPO treats defense as a formal optimization problem, resulting in a state-of-the-art shield that is both lightweight and highly transferable.

Executive Summary

RPO is a minimax optimization framework that generates a short, 20-token "defensive suffix" appended to system prompts to enforce safety. By explicitly training against an automated adversary during the optimization process, RPO achieves state-of-the-art robustness. It successfully reduces the attack success rate (ASR) on GPT-4 to just 6% and on Llama-2 to 0% across major benchmarks, all while maintaining the model's standard performance.

The Vulnerability Gap

Current LLM safety relies heavily on alignment training, teaching models to refuse harmful requests. However, adversaries continuously discover "adversarial suffixes" (like GCG) or "role-playing" templates that trick the model into ignoring its safety training.

Existing defenses generally fall into two inadequate categories:

  1. Input Filters: These check for known bad patterns or gibberish but are easily bypassed by natural language jailbreaks.
  2. Inference-time Checks: These often involve multiple LLM calls to sanitize an input, which introduces significant latency and cost.

The authors identified a critical gap: the absence of a formal, optimization-based objective that accounts for an adaptive adversary—one that dynamically alters its strategy to defeat the defense.

Methods: The RPO Framework

The core of RPO is a minimax objective, a classic concept drawn from game theory and adversarial training. The goal is to find a defensive suffix that minimizes the model's "safe loss" (the probability of refusing a prompt) even when an adversary is actively trying to maximize the "adversarial loss" (the probability of complying with a harmful request).

Illustration of the Robust Prompt Optimization (RPO) cycle, showing the interplay between defense and jailbreak optimization.

The RPO algorithm operates in a continuous two-step loop:

  1. Jailbreak Selection: For a given set of harmful instructions, the algorithm applies or generates the "worst-case" jailbreak that currently breaks the model.
  2. Discrete Optimization: The algorithm then updates the defensive suffix tokens to restore the model’s refusal behavior. Using a gradient-based approach, it swaps out tokens in the suffix for ones that most effectively lower the safe loss across all instructions and attacks.

The result is a universal, 20-token string that acts as a persistent "trigger" to keep the model in a safe state, regardless of the user's input.

Key Insights

  • Transferability: A striking finding is that a suffix optimized on an open-source model (like Llama-2-7B) transfers remarkably well to closed-source models like GPT-4. This suggests that refusal mechanisms across different LLMs share common latent features that a single suffix can activate.
  • Defense via "Triggering": Instead of merely filtering or blocking an attack, RPO essentially "reminds" the model of its safety training. The suffix acts as an anchor, keeping the model's attention firmly on its harmlessness objective.
  • Robustness to the Unknown: Because RPO optimizes against a variety of attacks simultaneously, the resulting suffix generalizes to unseen jailbreaks, holding up against novel role-playing and logic-based attacks.

Key Results

Evaluated on primary red-teaming benchmarks like JailbreakBench and HarmBench, RPO sets a new state-of-the-art for LLM defense.

Table detailing the Attack Success Rate (ASR) on JailbreakBench, demonstrating RPO's superior performance across multiple models and attack types.
  • Unprecedented ASR Reduction: RPO reduced the Attack Success Rate on GPT-4 from 50% down to 6% on JailbreakBench. For Llama-2-7B, it achieved a 0% ASR, effectively rendering the model fully robust against the benchmarked attacks.
  • High Efficiency: Unlike defenses requiring multiple LLM passes, RPO adds only 20 tokens to the prompt, resulting in negligible inference overhead.
  • Preserved Utility: Testing on standard benchmarks (MT-Bench and MMLU) confirmed that adding the RPO suffix does not degrade the model's ability to answer benign, helpful questions.

Limitations and Future Directions

While RPO represents a significant leap forward, it is not a silver bullet. Some models, like Vicuna-13B, remain partially vulnerable. Furthermore, the current scope is limited to text-based jailbreaks and does not yet address multimodal attacks (images/audio) or malicious code generation. Finally, as a system-level guardrail, the defense relies on the system prompt remaining hidden from the attacker.

Future research will explore optimizing semantically meaningful (human-readable) suffixes and extending this robust framework to protect complex LLM agents and multimodal systems.

Summary updated

BibTeX
@inproceedings{zhou2024robust,
  author = {Andy Zhou and Bo Li and Haohan Wang},
  title = {{Robust Prompt Optimization for Defending Language Models Against Jailbreaking Attacks}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=jXs6Cvpe7k},
}
Figure