Seedlabs
Source research

Jailbreak and Guard Aligned Language Models With Only Few In-Context Demonstrations

Zeming Wei, Yue Wang, Ang Li, Yichuan Mo, Yisen Wang · 2026 · 464 citationsRead the paper

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.

What the full text shows

Shown in the lab
  • In-Context Attack (ICA) increases Attack Success Rate (ASR) using only a single harmful demonstration. — 1% to 8% ASR for Vicuna (AdvBench); 3% to 19% ASR for Llama-2 (HarmBench) (1-shot ICA)
  • Increasing the number of harmful demonstrations significantly boosts jailbreak success rates. — 87% ASR for Vicuna; 46% ASR for GPT-4 (10-shot ICA)
  • Scaling demonstrations further increases ASR for closed-source models. — 81% and 65% ASR on two datasets (15 and 20-shot ICA on GPT-4)
Setup
Tested on Vicuna-7b-v1.5, Llama2-7b-chat, QWen-7b-v2, and GPT-4 0613 using AdvBench (~500 prompts) and HarmBench datasets.
How
The researchers proposed In-Context Attack (ICA), which prepends harmful query-response pairs to a target prompt, and In-Context Defense (ICD), which prepends refusal examples. They evaluated these methods using string detection and a fine-tuned Llama-13b judging model.
Limitations
Open-source 7b models have limited context windows (4096 tokens), restricting the number of possible demonstrations. · String detection for ASR is noted as potentially unreliable, requiring LLM-based or human re-checking.

Summarized by Gemma 4 from the open-access full text · 8 Nov 2026. Read it