Abstract
As Large Language Models (LLMs) become more integrated into critical applications, the risk of "jailbreaking"—crafting prompts to bypass safety guardrails—has intensified. Existing defense mechanisms, such as fine-tuning or static prompt filtering, often suffer from high computational costs, lack of adaptability, or excessive "over-defense." This paper presents the In-Context Adversarial Game (ICAG), a novel framework that enhances LLM safety through an iterative, agent-based game. By facilitating a dialogue between an "attacker agent" and a "defender agent," ICAG generates optimized system prompts that significantly lower jailbreak success rates (JSR) across various models without requiring fine-tuning. Our results show that ICAG-generated prompts are highly transferable and preserve the model's general reasoning capabilities.
Introduction
The rapid deployment of Large Language Models (LLMs) has introduced significant security challenges, most notably jailbreak attacks. These attacks involve sophisticated prompt engineering designed to elicit harmful or restricted content from the model. Current defensive strategies generally fall into three categories: fine-tuning, prompt filtering, and static safety instructions. However, fine-tuning is resource-intensive and often inaccessible for closed-source models. Prompt filtering can lead to "over-defense," where benign queries are incorrectly flagged. Static instructions fail to adapt to the evolving nature of adversarial attacks.
To address these limitations, we propose the In-Context Adversarial Game (ICAG). ICAG shifts the defense from model weights to the system prompt, utilizing the in-context learning capabilities of LLMs to create a dynamic and adaptive defense mechanism.
The In-Context Adversarial Game (ICAG) Framework
The ICAG framework operates as an iterative loop involving three primary components:
- The Attack Agent: This agent is tasked with generating and refining jailbreak prompts. It analyzes previous successful and failed attempts, using "insight extraction" to identify vulnerabilities and improve its hacking strategies.
- The Defense Agent: The defense agent observes the attack agent's successes and instances of over-defense. Through a "reflection" process, it identifies why a specific jailbreak succeeded or why a benign prompt was refused. It then generates safety-enhancing rules to mitigate these issues.
- The Assistant LLM: This component acts as a facilitator, summarizing the insights gained from both agents into a concise, actionable system prompt.
The game typically proceeds through approximately five to ten iterations. In each round, the attack agent becomes more sophisticated, forcing the defense agent to develop increasingly robust safety instructions. The final output is a single, optimized system prompt that can be prepended to any user query to ensure safe model interaction.
Experimental Evaluation
The effectiveness of ICAG was evaluated using several benchmark datasets to measure both safety and utility:
- AdvBench: 520 harmful instructions used to test the limits of safety filters.
- Self Reminder Data (SRD): 155 real-world jailbreak prompts.
- Xstest: 250 benign prompts designed to test for over-defense (unnecessary refusals).
- MMLU (Massive Multitask Language Understanding): Used to ensure the defense does not degrade the model's general intelligence.
The framework was tested across four prominent models: GPT-3.5-Turbo, Llama-3-8B, Vicuna-7B, and Mistral-7B.
Key Results
ICAG demonstrated superior performance compared to existing baselines across multiple metrics:
- Significant 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, ten iterations of ICAG (ICAG-10) reduced the success rate of several attack types to 0%.
- High Transferability: Safety prompts generated for one model (e.g., Llama) proved remarkably effective when applied to others (e.g., GPT-3.5 or Mistral), with the JSR only increasing by an average of 2.86%. This suggests that jailbreak vulnerabilities share common underlying patterns across different architectures.
- Preservation of Utility: Accuracy on the MMLU benchmark remained stable, indicating that ICAG enhances safety without compromising the model's helpfulness or reasoning ability.
- Mitigation of Over-Defense: By explicitly including benign-but-tricky queries in the adversarial loop, ICAG helps the defense agent learn the line between malicious intent and safe requests more accurately than standard filters.
Discussion and Insights
The success of ICAG highlights the power of Adversarial Training via Prompting. It proves that robust defense does not necessarily require gradient updates; rather, high-quality, iteratively refined instructions can achieve comparable or superior results. The "reflection" mechanism is crucial, as it allows the defense agent to move beyond generic safety commands and develop specific rules (such as "verify prompt context and intent") based on observed vulnerabilities.
Limitations and Future Work
Despite its success, ICAG has limitations. The framework currently relies on a static set of initial jailbreak prompts; if this set lacks diversity, the resulting defense may not generalize to entirely new attack vectors. Furthermore, the current implementation is text-only. As multimodal models (text + image/video) become more prevalent, the adversarial game must be expanded to handle "jailbreak images" or other media. Finally, while more cost-effective than fine-tuning, the iterative nature of ICAG still incurs computational and API costs.
Future research will focus on diversifying the initial attack sets and extending the ICAG framework to multimodal contexts to provide a more comprehensive defense for next-generation AI systems.
Summary updated