Skip to content

How Few-shot Examples Affect Prompt-based Defenses Against LLM Jailbreak AttacksHow Few-shot Demonstrations Affect Prompt-based Defenses Against LLM Jailbreak Attacks

arXiv· arXiv:2602.04294· Yanshu Wang, Shuaishuai Yang, Jingjing He, Tong Yang·Indexed by this site · 2026-10-12· Originally publishedDefenses

Quick read

Evaluation and benchmarks

Based on the paper PDF (AI-generated); refer to the original

Qwen-7B-Chat, AdvBench: RoP+FS-H Δ is +4.5, ToP+FS-G is -21.2 (Table 8).

Threat modelThe victim system is an LLM with RoP or ToP and optionally 3 few-shot demonstrations. The attacker rewrites queries with six jailbreak prompts such as AIM and DAN to elicit harmful outputs; the paper does not state white-box or black-box. Success is measured by Safe Rate, judged by Qwen3Guard-Gen-8B, with ASR=1−Safe Rate.

Questions
Few-shot is often used together with the system prompt as a jailbreak defense, but the direction of its interaction with RoP and ToP is unclear. The authors want to separately examine whether it strengthens or weakens these two types of prompt defenses.
Methods
The authors frame the defense as the concatenation of the system prompt and optional few-shot, explain the opposite directions with Bayesian posterior and attention dilution, and then compare RoP, ToP, and combinations with two types of 3 demonstrations each. The judge model is Qwen3Guard-Gen-8B.
Experiments and results
On AdvBench, few-shot improves RoP safety rates for some non-Think models (up to +4.5) and reduces most ToP configurations (as low as -21.2), but the table contains opposite signs. Across datasets, RoP+FS average Δ is negative. Think models are more susceptible to jailbreak-induced safety rate reductions across all configurations.
Limitations and future work
The authors state that they mainly evaluated 7-8B, the mechanism explanation remains a hypothesis, few-shot used only 3 examples, and GPT-4 and Claude were not evaluated. The results table does not provide numbers for Pangu-Embedded-1B; the paper does not report the number of repetitions or reviewer-human agreement.
Experimental setupPangu-Embedded-1B、Pangu-Embedded-7B et al. · AdvBench、HarmBench et al. · Safe Rate (SR)、Refusal Rate (RR) et al.
Evaluated models
Pangu-Embedded-1BPangu-Embedded-7BPangu-Embedded-7B-ThinkQwen-7B-ChatQwen3-8BQwen3-8B-ThinkQwen2.5-7B-InstructDeepSeek-7B-ChatLlama-2-7B-Chat
Benchmarks
AdvBenchHarmBenchSG-BenchXSTest
Metrics
Safe Rate (SR)Refusal Rate (RR)Attack Success Rate (ASR)
AI summaryThe authors' evaluation of multiple mainstream LLMs finds that few-shot examples increase the safety rate of role-oriented prompts (RoP) by up to 4.5%, while decreasing the defensive effectiveness of task-oriented prompts (ToP) by up to 21.2%. These results come from tests using six jailbreak attack methods across four safety benchmarks: AdvBench, HarmBench, SG-Bench, and XSTest. The authors argue that RoP's improvement stems from few-shot examples reinforcing the role identity, while ToP's degradation is due to attention being diverted from task instructions, and accordingly provide recommendations for deploying prompt-based defenses in real-world LLM applications.

The authors' evaluation of multiple mainstream LLMs finds that few-shot examples increase the safety rate of role-oriented prompts (RoP) by up to 4.5%, while decreasing the defensive effectiveness of task-oriented prompts (ToP) by up to 21.2%. These results come from tests using six jailbreak attack methods across four safety benchmarks: AdvBench, HarmBench, SG-Bench, and XSTest. The authors argue that RoP's improvement stems from few-shot examples reinforcing the role identity, while ToP's degradation is due to attention being diverted from task instructions, and accordingly provide recommendations for deploying prompt-based defenses in real-world LLM applications.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    The authors examine whether few-shot strengthens or weakens the two types of prompt defenses, RoP and ToP.

    The interaction direction and mechanism between few-shot demonstrations and the two types of system prompt defenses (RoP, ToP) remain unclear.

    • Scenario: The authors state that LLMs aligned via RLHF, DPO, and Constitutional AI can still be bypassed by jailbreak prompts, eliciting harmful outputs in sensitive applications. Prompt defenses are used because they do not require retraining.
    • Existing gap: The authors state that SG-Bench found few-shot can induce harmful responses, but treated it as an independent factor without separately examining its interaction with RoP and ToP. Many-shot and improved few-shot jailbreaking treat few-shot as an attack.
    • Hypothesis: The authors hypothesize that safe few-shot will increase RoP's safety rate and decrease ToP's safety rate. The mechanisms are, respectively, a strengthened role posterior and diluted attention to the task instruction.
    • This paper's approach: The authors compare no defense, RoP, ToP, and combinations with two types of few-shot, and provide Bayesian in-context learning and attention analysis, as well as deployment recommendations.
    • Threat model:
      • Goal: Jailbreak prompts aim to bypass safety alignment and elicit harmful, unethical, or dangerous outputs.
      • Knowledge: The paper does not label the six evaluated attacks as white-box, black-box, or no-box.
      • Capability: The attacks apply AIM, DAN, Evil Confident, Prefix Rejection, Poems, Refusal Suppression to benchmark queries. Defenses only modify the system prompt and optionally few-shot, without retraining the model.
      • Victim system and judgment: The victim system is the LLM under test. Safe Rate is the proportion of responses judged safe, and ASR is defined as 1 minus Safe Rate. The judge model is Qwen3Guard-Gen-8B.
  2. What related research exists?

    Related work separately covers alignment, benchmarks, jailbreaks, and prompt defenses; the authors claim interactions have not been systematically compared.

    The paper reviews by topic and places the gap on the interaction between few-shot and different system prompts.

    Safety alignment

    • Feedback alignment: RLHF (Ouyang et al., 2022), Safe RLHF (Dai et al., 2024), Constitutional AI (Bai et al., 2022), DPO (Rafailov et al., 2024) use preferences to train safe behavior. The paper also mentions Safety-tuned LLaMAs (Bianchi et al., 2024).
    • Limits of the paper's paraphrasing: Wolf et al. (2024) state that alignment often only affects the first few tokens. Qi et al. (2024) state that benign fine-tuning can also harm safety. Huang et al. (2024) and Mo et al. (2024) discuss generation exploitation and fragile patterns.

    Benchmarks and attacks

    • Benchmarks: AdvBench, HarmBench, JailbreakBench, SafetyBench, XSTest, SG-Bench, etc. The paper states the most relevant is SG-Bench: it contains RoP, ToP, and few-shot, but does not separately measure the interaction between few-shot and the two system prompts.
    • Attacks and red teaming: Role-playing (DAN, AIM), gradient suffixes (GCG, AutoDAN), black-box iterative (PAIR, Tree of Attacks), and many-shot jailbreaking (Anil et al., 2024). Perez et al. (2022), MART, HARM, RedAgent use models for red teaming. The paper states many-shot treats demonstrations as an attack, not a defense component.

    Prompt defenses and few-shot

    • Defenses: self-reminder (Xie et al., 2023), intention analysis (Zhang et al., 2024), Llama Guard, NeMo Guardrails, SmoothLLM, etc. The RoP and ToP formulations come from SG-Bench. These methods are not comparison rows in this paper's results tables.
    • Demonstrations and theory: Brown et al. (2020), Min et al. (2022) discuss in-context demonstrations. Zheng et al. (2024)'s improved few-shot jailbreaking and BadChain show demonstrations can bypass defenses or implant backdoors. Explanations come from Xie et al. (2022), Liu et al. (2024)'s lost in the middle, Xiao et al. (2024)'s attention sink.
    • Baselines and benchmarks: No defense, RoP alone, ToP alone, and each with FS-General or FS-Harmful. Data are AdvBench, HarmBench, SG-Bench, XSTest.

    The authors state that no existing benchmark system examines this interaction, and state this is the first systematic study. Section 6.3 states: SG-Bench's claim that few-shot can induce harmful responses mainly corresponds to ToP; RoP+FS is mostly positive on non-Think models.

  3. How does the paper address this problem?

    The authors formalize the interaction between RoP/ToP and few-shot, and test it with combinatorial experiments.

    The authors use Bayesian in-context learning and attention analysis to predict that few-shot has opposite effects on RoP and ToP, and then test with all prompt combinations.

    Problem Setting

    • Defense form: The defense includes a system prompt s, and optional few-shot F. F is k input-output pairs. The response is generated by concatenating s, F, and query q. The safety rate is the probability that the response falls into the safe set.
    • Two types of prompts: RoP performs identity transformation, exemplified in the paper as writing the model as a safe assistant. ToP provides task instructions, exemplified as requiring safe responses. Table 3 has templates; we do not copy sentences here.
    • Interaction: Under the same s, the difference in Safe Rate before and after adding F is denoted Δ. The authors hypothesize that Δ for RoP is positive and for ToP is negative.
    • Definition: Δ(s, F)=SafeRate(s ⊕ F)−SafeRate(s), i.e., the change in safety rate from concatenating few-shot.

    Bayesian Update

    • Generative hypothesis: The authors follow Xie et al., writing the pretraining distribution as a mixture over latent concepts θ, where θ determines the mapping from input to output.
    • Posterior: k demonstrations update the prior to a posterior, and predictions for new queries integrate over the posterior. Section 3.2 contains a Proof.
    • RoP: Proposition 2 states that RoP concentrates the prior on assistant-like concepts. Safe responses have higher likelihood under safe concepts, so safe few-shot amplifies that posterior.
    • Unmeasured internal quantities: The paper does not report internal posteriors or concept probabilities. This section is an explanatory framework.

    Attention Dilution and Positional Bias

    • Entropy: Lemma 4 states that for length n, softmax attention entropy does not exceed log n, with equality when uniformly distributed.
    • Dilution upper bound: E[αinstr]=O(L0/(L0+LF)). L_0 is the ToP instruction length, L_F is the total few-shot length. The authors state that as L_F increases, attention to instruction tokens decreases, and instruction-following accuracy worsens.
    • Position: The authors cite lost in the middle, stating that after few-shot insertion, the task instruction is pushed to the middle, and retrieval accuracy can drop below 50%. Theorem 7 states that under causal masking, earlier tokens accumulate attention layer by layer, consistent with attention sink, so RoP written at the beginning is less likely to be washed out by later few-shot.
    • Testable predictions: Section 3.5 predicts that as demonstrations increase, RoP's Δ rises and ToP's Δ falls. RoP benefits from both contents, and FS-Harmful is sometimes stronger. ToP's decline is mainly driven by length. Deeper models have stronger positional bias.

    Experimental Configuration and Evaluation

    • Materials: FS-G is three benign dialogues. FS-H is three demonstrations of refusing harmful requests. Combinations are no defense, RoP alone, ToP alone, and four configurations adding FS-G or FS-H.
    • Attack rewriting: Each benchmark query is rewritten with the six jailbreak rewrites from Section 4.3. The paper does not describe these attacks as an optimization loop, nor does it report query counts.
    • Evaluation: Metrics are Safe Rate, Refusal Rate, and ASR equals 1 minus Safe Rate. The reviewer model is Qwen3Guard-Gen-8B. The paper does not specify temperature, thresholds, or repetitions.
    • Fixed settings: The experiments fix k=3 and do not sweep over the number of examples or depth as in Section 3.5.
  4. What experiments did the paper conduct?

    On AdvBench, the Δ in Table 8 is not all in the same direction: RoP's highest is +4.5, ToP's lowest is -21.2.

    Experimental setup

    • Models under test: Table 1 lists Pangu-Embedded-1B, Pangu-Embedded-7B, Pangu-Embedded-7B-Think, Qwen-7B-Chat, Qwen3-8B, Qwen3-8B-Think, Qwen2.5-7B-Instruct, DeepSeek-7B-Chat, Llama-2-7B-Chat. The results tables do not report Pangu-Embedded-1B.
    • Benchmarks: AdvBench 520 items; HarmBench 300 items; SG-Bench 1,442 items, 6 categories of safety issues; XSTest 450 items, measuring over-refusal. Each benchmark has six jailbreaks applied. The paper only writes out that AdvBench becomes 3,120 items (520×6).
    • Attacks and defenses: Attacks are AIM, DAN, Evil Confident, Prefix Rejection, Poems, Refusal Suppression. Configurations are no defense, RoP, ToP, RoP+FS-G, RoP+FS-H, ToP+FS-G, ToP+FS-H. Each type of few-shot has 3 demonstrations.
    • Metrics: Safe Rate is the proportion judged safe. Refusal Rate is the proportion of explicit refusals; the paper does not specify the determination rule. ASR is defined as 1 minus Safe Rate. The tables mainly report Safe Rate.
    • Judging: Qwen3Guard-Gen-8B, the authors state following the SG-Bench protocol. The paper does not report the threshold, temperature, number of repetitions, or agreement between the judge and humans.

    Main results

    On AdvBench, few-shot relative to RoP or ToP alone has the following Safe Rates (Table 8). This table does not include Pangu-Embedded-7B-Think, Qwen2.5-7B-Instruct, DeepSeek-7B-Chat, Pangu-Embedded-1B.

    Swipe horizontally to read the table

    ModelRoP+FS-GRoP+FS-HToP+FS-GToP+FS-H
    Pangu-Embedded-7B94.9%→99.2% (+4.3)94.9%→98.8% (+3.9)96.0%→94.1% (-1.9)96.0%→92.6% (-3.4)
    Qwen3-8B98.8%→99.8% (+1.0)98.8%→96.9% (-1.9)93.1%→97.8% (+4.7)93.1%→82.4% (-10.7)
    Llama-2-7B-Chat95.5%→95.1% (-0.4)95.5%→97.7% (+2.2)92.7%→83.0% (-9.7)92.7%→92.8% (+0.1)
    Qwen-7B-Chat94.6%→95.2% (+0.6)94.6%→99.1% (+4.5)96.5%→75.3% (-21.2)96.5%→82.9% (-13.6)
    Qwen3-8B-Think90.8%→85.8% (-5.0)90.8%→77.6% (-13.2)77.4%→72.5% (-4.9)77.4%→61.5% (-15.9)
    • The authors state this confirms few-shot strengthens RoP and weakens ToP, and give average Δ: for RoP, FS-G/FS-H are +2.0% and +2.2%; for ToP, −6.6% and −8.7%.
    • The signs in the table are not all consistent: RoP has negative Δ, ToP has positive Δ. The Think model row is all negative. The authors state Think models violate the standard prediction.
    • The abstract and the introduction/conclusion write the upper bound of the RoP increase differently, corresponding respectively to Qwen-7B-Chat's RoP+FS-H and Pangu-Embedded-7B's RoP+FS-G. The conclusion's upper bound of the ToP decrease corresponds to Qwen-7B-Chat's ToP+FS-G.

    RoP and ToP under jailbreaks

    • No defense: Table 5, AdvBench. Llama-2-7B-Chat goes from 99.8% to 86.5%. Qwen3-8B-Think goes from 97.3% to 52.0%, which the authors state is a drop of 45.3 percentage points. DeepSeek-7B-Chat goes from 54.8% to 21.7%. The authors state an average drop of 15–60 percentage points, without giving a calculation table.
    • Attack types: Table 6, only Pangu-Embedded-7B. Prefix Rejection is 63.1%, AIM is 72.1%, Poems is 98.5%, Evil Confident is 97.3%. The authors state the first two bypass alignment most effectively, and the latter two have limited success.
    • Adding RoP/ToP: Table 7. Qwen3-8B-Think goes from 52.0% to RoP 90.8%, ToP 77.4%. The authors state RoP improves by an average of 15.2 percentage points and ToP by 12.8 percentage points, with RoP slightly higher. In the same table, Pangu-Embedded-7B has ToP 96.0%, RoP 94.9%, and Qwen-7B-Chat has ToP 96.5%, RoP 94.6%.

    Cross-dataset and HarmBench

    • SG-Bench: Figure 3's caption states the average Safe Rate of RoP+FS-General is 0.88, ToP alone is 0.82, ToP+FS is 0.79 and 0.78. The paper does not specify which models are averaged.
    • Cross-dataset Δ: Table 11 gives RoP+FS-G −0.6%±3.1%, RoP+FS-H −0.9%±5.4%, ToP+FS-G −3.0%±7.6%, ToP+FS-H −4.0%±5.4%. This differs from the positive RoP average given on AdvBench in Section 5.4.
    • HarmBench: Table 13. Pangu-7B's RoP goes from 93.2% to RoP+FS 96.5%. Qwen-7B's ToP goes from 94.9% to ToP+FS 80.7%, which the authors state is −14.2%. Qwen3-8B's ToP goes from 84.8% to ToP+FS 93.2%, which is not a decrease. The paper does not specify whether FS is General or Harmful. The Think row's RoP+FS is 86.1%, lower than RoP's 89.6%.

    XSTest and Think mode

    • Over-refusal: Table 14, under jailbreak conditions; the paper does not specify the defense configuration. Pangu-7B's Safe Rate is 97.4%, Refused Rate is 78.0%, Gap is 75.4%. Llama-2-7B is 95.7%, 83.4%, 79.1%. Qwen3-8B-Think is 60.1%, 34.5%, −5.4%. The authors state the first two models have Gap greater than 70%. The authors state the Think model has a negative Gap, both agreeing to requests that should be refused and refusing benign requests.
    • Think comparison: In Table 4, Pangu-Embedded-7B-Think is 75.0%, non-Think is 99.8%. In Section 5.9, the authors state Think models' attack drop is 20–45% larger than non-Think, and regardless of RoP or ToP, the few-shot interaction is negative. Section 6.1 juxtaposes Qwen3-8B-Think's 52.0% with 75.6%, and Pangu-7B-Think's 75.0% with 99.8%. The former corresponds to Table 5's jailbreak, no defense; the latter corresponds to Table 4's direct queries.
    • Authors' explanation: Section 6.1 uses dual-process theory and instruction hierarchy to explain Think mode and the RoP/ToP asymmetry. This is the authors' explanation, not additional measurements.

    Other ablations and analyses

    • Table 12, RoP+FS-G's Δ: Pangu-7B on Adv/Harm/SG/XS is +4.3, +3.3, +2.6, −0.7. Qwen3-8B-Think is −5.1, −3.5, −9.4, −5.5. On Adv, Qwen-7B is +0.5, while Table 8 writes +0.6.
    • Table 9 writes the observations as Δ_RoP +2.0% to +4.5%, Δ_ToP −6.6% to −21.2%, not including the opposite-sign cells in Table 8. Table 10 writes first-token attention greater than 10%; the paper does not report self-measured attention.
    • Section 5.5 case study: the authors state RoP+FS-Harmful refuses AIM-type requests, and ToP+FS-General does not refuse on Qwen-7B-Chat. The prompts and outputs are not reproduced here.
    • Table 6's remaining attacks, still Pangu-Embedded-7B, AdvBench: DAN 89.2%, Refusal Suppression 85.6%, no attack 99.8%.
    • In Section 5.4, the authors state Pangu-Embedded-7B's +4.3% is consistent with a lower initial posterior. The paper does not report posterior values.
  5. What are some points that can be further explored?

    The authors claim scale, mechanisms, number of demonstrations, and closed-source models remain for future work.

    Limitations and future directions noted by the authors

    • Model scale: The authors state that the main evaluations use 7–8B models, and larger scales may exhibit different patterns (Section 6.4).
    • Mechanism validation: The authors state that role reinforcement and attention dilution are hypotheses supported by empirical patterns; attention visualization or probing would be needed to strengthen confirmation (Section 6.4).
    • Number of demonstrations: The authors state that only 3 were used, and different numbers may have different effects (Section 6.4).
    • Closed-source models: The authors state that GPT-4 and Claude were not evaluated due to access restrictions (Section 6.4).
    • Future directions: The authors list attention analysis, automatic configuration selection based on model characteristics, evaluation of models larger than 70B and closed-source models, examination of demonstration quantity and content, and further analysis of Think mode (Section 6.5).

    Experimental coverage

    • Models appearing in the results tables are Llama-2-7B-Chat, Pangu-Embedded-7B, Pangu-Embedded-7B-Think, Qwen-7B-Chat, Qwen3-8B, Qwen3-8B-Think, Qwen2.5-7B-Instruct, DeepSeek-7B-Chat. Table 1 also lists Pangu-Embedded-1B, but the results tables do not give numbers for it.
    • Benchmarks are AdvBench, HarmBench, SG-Bench, XSTest. The jailbreak methods are the six in Table 2. Related work discusses GCG, AutoDAN, PAIR, but the experimental section does not report numbers for these methods.
    • Defense configurations are no defense, RoP, ToP, and combinations with FS-General, FS-Harmful. Few-shot is 3 demonstrations (Section 4.4, Section 6.4). Section 3.5 predicts effects vary monotonically with the number of demonstrations and strengthen with model depth; the experiments do not report these two comparisons.
    • The judge model is Qwen3Guard-Gen-8B. The paper does not report the number of repetitions, sampling settings, refusal determination rules, or agreement between the judge and humans.
    • The interaction results in Table 8 include 5 models. Table 13's RoP+FS, ToP+FS do not specify whether FS-General or FS-Harmful. Table 14 does not specify the defense configuration.
  6. Summarize the main content of the paper

    Few-shot can increase RoP and decrease ToP, but the table contains opposite signs, and the Think model is lower.

    The authors evaluate how few-shot demonstrations change the effectiveness of RoP and ToP as defenses against jailbreaks.

    • Setup: The defense is the concatenation of the system prompt and optional few-shot. RoP specifies the safe assistant identity, ToP specifies the safe response task. FS-General and FS-Harmful each have 3 demonstrations. Safe Rate is judged by Qwen3Guard-Gen-8B, and ASR is 1 minus Safe Rate.
    • Jailbreaks and single defenses: On AdvBench, with no defense, Llama-2-7B-Chat's Safe Rate is 86.5%, and DeepSeek-7B-Chat is 21.7% (Table 5). The authors state RoP and ToP improve by an average of 15.2 and 12.8 percentage points. In Table 7, Pangu-Embedded-7B and Qwen-7B-Chat have ToP higher than RoP.
    • Interaction: In Table 8, Qwen-7B-Chat's RoP+FS-H relative to RoP is +4.5, and ToP+FS-G relative to ToP is -21.2. The authors state that on AdvBench, RoP is strengthened on average and ToP is weakened on average, but the table has opposite signs, and the Think model row is entirely negative. The abstract's RoP upper bound is 4.5%, while the introduction and conclusion write 4.3%.
    • Other benchmarks: The caption states that on SG-Bench, RoP+FS-General's average Safe Rate is 0.88 (Figure 3). Table 11's cross-dataset RoP+FS average Δ is negative. On HarmBench, Qwen-7B's ToP to ToP+FS goes from 94.9% to 80.7%, which the authors state is a drop of 14.2 percentage points. In the same table, Qwen3-8B's ToP+FS is higher than ToP, and the paper does not specify the FS variant (Table 13).
    • Authors' conclusions: The authors recommend using RoP with few-shot for non-Think models, and not adding few-shot when using ToP. The authors state Think mode has lower safety rates on direct queries, jailbreaks, and few-shot interactions. The mechanism explanations are written as hypotheses consistent with the observed patterns.

Related papers

Show 3 more papers
Read originalarxiv.org