Dynamic Deep Prompt Optimization for Defending Against Jailbreak Attacks on LLMs
Organizations: Michigan Technological University · Miami University · Kansas State University
Abstract
Large Language Models (LLMs) demonstrate impressive capabilities across many applications but remain vulnerable to jailbreak attacks, which elicit harmful or unintended content. While model fine-tuning is an option for safety alignment, it is costly and prone to catastrophic forgetting. Prompt optimization has emerged as a promising alternative, yet existing prompt-based defenses typically rely on static modifications (e.g., fixed prefixes or suffixes) that cannot adapt to diverse and evolving attacks. We propose Dynamic Deep Prompt Optimization (DDPO), the first jailbreak defense based on deep prompt optimization. DDPO uses the target LLM's own intermediate layers as feature extractors to dynamically generate defensive embeddings via a lightweight multilayer perceptron. These tailored embeddings are then injected into a subsequent intermediate layer, enabling an input-dependent defense without modifying the LLM's weights. This design ensures high adaptability with minimal computational overhead. Experiments on a diverse set of models and attacks demonstrate that DDPO significantly outperforms static prompt optimization methods, particularly on weakly aligned models and when handling semantically ambiguous benign prompts, successfully distinguishing them from genuinely harmful requests.
Figures & tables
| Attack Success Rate (%) | Utility (%) | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Model | Defense | PH | PEZ | UAT | GCG | AP | GBDA | GCG-M | PAIR | HC | Average | Benign | MMLU |
| Llama3 | None | 1.29 | 3.12 | 5.54 | 7.25 | 6.92 | 4.02 | 7.14 | 5.06 | 20.62 | 6.77 | 94.45 | 65.46 |
| PAT | 0.00 | 2.17 | 2.61 | 4.35 | 4.78 | 3.48 | 5.65 | 4.78 | 23.48 | 5.70 | 75.80 | 42.81 | |
| RPO | 0.00 | 1.30 | 1.74 | 2.17 | 1.74 | 2.17 | 0.87 | 3.04 | 10.00 | 2.56 | 70.60 | 47.65 | |
| DRO | 0.00 | 1.74 | 1.74 | 1.30 | 0.87 | 1.30 | 0.00 | 0.87 | 6.96 | 1.64 | 92.40 | 47.15 | |
| DDPO | 2.61 | 1.30 | 0.00 | 0.43 | 0.00 | 0.43 | 0.43 | 0.87 | 0.87 | 0.77 | 97.80 | 63.53 | |
| SDPO (Static) | DDPO (Dynamic) | |||
|---|---|---|---|---|
| Model | ASR | BPR | ASR | BPR |
| Llama3 | 12.32 | 98.60 | 0.77 | 97.80 |
| Deepseek | 22.90 | 86.80 | 0.39 | 94.60 |
| Vicuna | 47.20 | 96.00 | 0.68 | 95.80 |
| Llama2 | 9.52 | 70.00 | 1.40 | 93.20 |
| Openchat | 79.32 | 99.00 | 0.97 | 95.60 |
| Model | Metric | |||
|---|---|---|---|---|
| Llama3 | ASR | 0.77 | 1.50 | 0.72 |
| BPR | 97.8 | 98.0 | 97.4 | |
| Deepseek | ASR | 0.39 | 1.26 | 0.34 |
| BPR | 94.6 | 96.2 | 96.4 | |
| Vicuna | ASR | 0.68 | 1.35 | 0.97 |
| BPR | 95.8 | 95.4 | 96.6 |
Jailbreak Defense
Jailbreak defense studies how to stop adversarial prompts from eliciting harmful outputs while preserving helpful behavior.
See all 60 papers