Defending Jailbreak Prompts via In-Context Adversarial Game

Yujun Zhou, Yufei Han, Haomin Zhuang, Kehan Guo, Zhenwen Liang, Hongyan Bao, Xiangliang Zhang

TL;DR

The In-Context Adversarial Game (ICAG) is a novel, training-free defense framework that uses an iterative "cat-and-mouse" game between LLM agents to evolve robust safety instructions. By simulating attacks and refining defenses through in-context learning, ICAG significantly reduces jailbreak success rates and produces defensive prompts that transfer effectively across different models.

What Problem Does This Paper Address?

Large Language Models (LLMs) are notoriously susceptible to "jailbreak" attacks—cleverly engineered prompts designed to bypass safety guardrails and elicit harmful content. Current defenses typically fall into three buckets: static prompt filtering (which often leads to over-defensiveness), fine-tuning (which is computationally expensive and impossible for closed-source models), or static safety instructions (which fail to adapt to new, unseen attack vectors).

The authors address the need for a dynamic, adaptive, and transferable defense mechanism. They ask: How can we build a defense that evolves as fast as the attacks, without the overhead of retraining the entire model?

Methods

The core of the paper is the In-Context Adversarial Game (ICAG). Instead of updating model weights, ICAG updates the system prompt through an iterative process involving two primary agents:

  1. The Attack Agent: Its goal is to generate successful jailbreaks. It uses a combination of automated prompt generation (AutoDAN) and "agent learning." It analyzes why previous attempts failed by retrieving similar successful prompts (using Faiss for similarity search) and extracting "insights" to refine its strategy.
  2. The Defense Agent: Its goal is to block the attacker. It employs a Reflection process where it compares successful jailbreaks to similar benign queries to understand the "why" behind the failure. It then extracts these insights into a set of rules that form a new, more robust system prompt.
Figure 2: The overall workflow of In-Context Adversarial Game.

Unlike previous methods like "Self-Reminder," which use a single round of reasoning, ICAG is iterative. The two agents play against each other for multiple rounds (typically 5-10) until the defense converges.

Figure 1: Comparison between our proposed ICAG and the Self Reminder from (Xie et al., 2023). (a) Self Reminder follows a single round of reasoning and prompts refinement for defending. (b) Our approach involves iterative attack and defense cycles, extracting more insights for both attacking and defending.

Datasets

The researchers evaluated ICAG using several established benchmarks:

  • AdvBench: A collection of 520 harmful instructions used to test if the model will comply with dangerous requests.
  • Self Reminder Data (SRD): A dataset of 155 "in-the-wild" jailbreak prompts.
  • Xstest: Used to measure "over-defense"—the rate at which a model incorrectly refuses safe, benign prompts.
  • MMLU: A massive multitask language understanding benchmark used to ensure that the added defensive prompts don't degrade the model's general intelligence or helpfulness.

Key Insights and Ideas

  • Adversarial Training via ICL: The most significant "aha" moment is that the principles of adversarial training (traditionally used in deep learning to harden models) can be applied to LLMs entirely through In-Context Learning (ICL). You don't need to touch the weights to make the model significantly more robust.
  • The Power of Reflection: The defense agent's ability to reflect on why a specific jailbreak worked—by comparing it to a "near-miss" benign prompt—allows it to generate highly specific and effective safety rules.
  • Defense Transferability: A surprising finding is that defensive system prompts evolved on one model (e.g., GPT-3.5) work remarkably well when applied to entirely different models (e.g., Mistral or Vicuna). This suggests that jailbreak vulnerabilities often exploit common logical fallacies or instruction-following behaviors shared across LLMs.

Key Results

  • JSR Reduction: ICAG reduced the Jailbreak Success Rate (JSR) by an average of 7.99% compared to the best existing baseline methods. On GPT-3.5, it reduced JSR to under 5%, even reaching 0% in several attack scenarios.
  • Convergence: The adversarial game typically converges within 5 to 10 iterations. As shown in the validation curves, JSR drops sharply in the first few rounds before stabilizing.
  • High Transferability: When a system prompt generated for one model was applied to three others, the JSR only increased by an average of 2.86%, proving the defense is not model-specific.
  • Preserved Utility: Testing on MMLU showed that ICAG-enhanced prompts had virtually no impact on the model's general helpfulness or accuracy on standard tasks.

Limitations and Future Work

The authors acknowledge a few key limitations:

  • Static Adversary Assumption: The game assumes a relatively static set of initial attack strategies. If an attacker uses a completely novel, multimodal, or context-rich approach not represented in the starting set, the defense might not generalize.
  • Text-Only Focus: The current framework is designed for text-based interactions and hasn't been tested on multimodal jailbreaks (e.g., using images to bypass safety).
  • Initial Prompt Quality: The success of the iterative game depends heavily on the diversity and quality of the initial jailbreak prompt set ($JP_0$).

Future work aims to scale these strategies to multimodal contexts and explore even more dynamic threat landscapes where the adversary adapts in real-time.

Summary updated

BibTeX
@inproceedings{zhou2024defending,
  author = {Yujun Zhou and Yufei Han and Haomin Zhuang and Kehan Guo and Zhenwen Liang and Hongyan Bao and Xiangliang Zhang},
  title = {{Defending Jailbreak Prompts via In-Context Adversarial Game}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.1121},
}
Figure