Jailbreak and Guard Aligned Language Models With Only Few In-Context Demonstrations
Zeming Wei, Yue Wang, Ang Li, Yichuan Mo, Yisen Wang
Peking University
Key points
From the paper's conclusion- We first provide theoretical insights to illustrate how minimal in-context demonstrations can efficiently alter safety alignment.
Abstract
Large Language Models (LLMs) have demonstrated remarkable success across diverse applications, yet their susceptibility to malicious exploitation remains a critical challenge. Notably, LLMs are known to be vulnerable to jailbreaking attacks, where adversaries craft malicious inputs to induce harmful or unethical outputs. In this paper, motivated by the unique effectiveness and scalability of In-Context Learning (ICL) in LLMs, we explore its potential to modulate the safety alignment of LLMs. Specifically, we propose the In-Context Attack (ICA), which employs harmful demonstrations to subvert LLMs' safety, and the In-Context Defense (ICD), which bolsters their resilience through examples that demonstrate refusal to produce harmful responses. By adjusting the distribution of safety in LLM outputs through adversarial demonstrations, our proposed in-context attack and defense facilitate effective manipulation of their alignment. We first provide theoretical insights to illustrate how minimal in-context demonstrations can efficiently alter safety alignment. Empirically, we validate ICA and ICD across multiple models, datasets, and attack baselines, showing their efficacy and scalability for red-teaming evaluations and robust safeguards for real-world deployment. Overall, our work unveils the pivotal yet understudied role of ICL in LLM safety, opening new avenues for understanding and improving them.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- GuardrailAgent: An Agentic Framework for Jailbreak DefensearXiv · 2026
- Survey on LLM Safety: Attacks, Defenses, Alignment, Metrics, and GuardrailsMachine Learning · 2026
- From LLMs to MLLMs to Agents: A Survey of Emerging Paradigms in Jailbreak Attacks and Defenses within LLM EcosystemACM Transactions on Knowledge Discovery from Data · 2026
- JailBound: FOL-Guided Jailbreak Evaluation for Exploring LLM Behavioral BoundariesarXiv · 2026
- Prompt-Based Jailbreaking of Leading LLM Chatbots: A Survey of Attacks and DefensesIEEE Transactions on Artificial Intelligence · 2026
- Efficient Indirect LLM Jailbreak by Leveraging Visual Modality.IEEE transactions on pattern analysis and machine intelligence · 2026