Large language models (LLMs) remain vulnerable to jailbreak attacks in which adversarial prompts induce harmful outputs. Existing defenses often require access to the model internals or additional training, limiting their applicability for service providers deployed through black-box APIs. In this paper, we propose DYNASHIELD, a moving target defense framework that improves robustness by customizing decoding hyperparameters and system prompts at inference time. DYNASHIELD includes two key steps: (1) it identifies decoding configurations that reduce attack success probability, and (2) it probabilistically samples from a weighted configuration pool to introduce controlled variability in model behavior. We evaluate DYNASHIELD across 7 open-source LLMs under 4 state-of-the-art jailbreak attacks, using adversarial prompts from AdvBench. Results show substantial reductions in attack success rate compared with 7 baseline defenses, while maintaining response quality and incurring minimal inference overhead. Because DYNASHIELD operates solely through exposed runtime controls, it requires no retraining or model-internal access. These results suggest that safety-aware dynamic decoding is a promising and practically lightweight defense mechanism for black-box LLM deployments.
Figures & tables
Methods
Training-Free
LLM-Based Defense
Dynamic Adaptation
Dynamic Att. [ 4 ]
✓
×
✓
Morphence [ 5 ]
×
×
✓
SafeDecoding [ 6 ]
×
✓
×
DynaShield
✓
✓
✓
TABLE I: Comparison of representative LLM defenses along three dimensions: training requirement, LLM involvement, and dynamic adaptation capability.
Fig. 1: Overview of DynaShield . The framework implements an MTD strategy by dynamically randomizing decoding configurations at inference time. (1) During initialization, the system collects jailbreak prompts, generates decoding hyperparameter candidates (e.g., Top- k , Top- p ), and evaluates them via refusal checks to build a weighted configuration pool. (2) At inference time, DynaShield randomly samples a decoding configuration Cfg for each user query Q and generates a response r=M(Q,Cfg) using the target LLM API M , thereby mitigating adversarial prompt exploitation through unpredictability.
Fig. 2: Next-token sampling strategies. Left: The model’s decoding pipeline. We focus on the final sampling step, where top- k and top- p are applied before a token is drawn. Middle: top- k sampling with k=4 , in which only the four highest-probability tokens are retained and their probabilities renormalized over the reduced vocabulary; all remaining tokens are excluded from selection. Right: top- p sampling with p=0.5 , in which the smallest set of tokens whose cumulative probability mass meets or exceeds p is selected, and probabilities are renormalized over this nucleus.
Fig. 3: Heatmap of successful jailbreaks on Dolphin and Llama2 models using AdvBench prompts [ 2 ] under various decoding strategies, without defenses. The number in each cell indicates the number of successful adversarial prompts.
Attack
Different Defenses
DynaShield
ICD
PPL
Retokenization
SafeDecoding
Self-Exam
Self-Reminder
SMOOTH-LLM
No-Defense
Guard-3-8B
AutoDAN
0.10
0.08
0.81
0.05
0.08
0.03
0.38
0.08
0.02
DeepInception
0.34
0.72
0.62
0.68
0.72
0.64
0.78
0.72
0.14
GCG
0.29
–
0.79
0.47
0.47
0.34
0.55
0.47
0.19
PAIR
0.24
0.20
0.35
0.20
0.19
0.14
0.24
0.20
0.07
TABLE II: ASRs comparison of attacks against defenses on different models.
Fig. 4: Efficiency and response quality across different defense methods.
Model
Defense
PAIR
AutoDAN
GCG
DeepInception
Vicuna-7B
Random
0.24
0.12
0.10
0.06
Fixed
0.24
0.10
0.08
0.04
DynaShield
0.06
0.04
0.00
0.00
Dolphin-Llama2-7B
Random
0.66
0.36
0.48
0.46
Fixed
0.64
0.30
0.52
0.56
DynaShield
0.32
0.10
0.16
0.00
TABLE III: Comparison of ASRs for various attacks against defenses on representative models Vicuna-7B , Dolphin-Llama2-7B and Llama2-7B-Chat
Attack
Different Defenses
DynaShield
ICD
PPL
Retokenization
SafeDecoding
Self-Exam
Self-Reminder
No-Defense
DeepInception
0.00
0.06
0.56
0.04
0.06
0.66
0.06
0.00
+Decoding-Aware
0.20
0.10
0.74
0.10
0.06
0.90
0.10
0.00
GCG
0.06
–
0.00
0.06
0.06
0.08
0.06
0.10
+Decoding-Aware
0.46
–
0.50
0.38
0.34
0.58
0.38
0.10
PAIR
0.34
0.54
0.46
0.52
0.44
0.58
0.54
0.16
TABLE IV: Comparison of ASRs for various attacks with decoding-aware adjustments against defense mechanisms on the Dolphin-Llama2-7B model, measured against the baseline of no defense. Following the protocol in Section V-A , the PPL–GCG entries are marked “–” and excluded from comparison.
Fig. 5: Effect of decoding strategies on the number of successful jailbreak examples for Vicuna-7B models against DeepInception, GCG, PAIR, and AutoDAN attacks without any defenses.
Fig. 6: Kernel density estimations show the distribution of success and unsuccess attacks on Vicuna-7B , reflecting the impact of different decoding schemes.
Fig. 7: Attention maps from Dolphin-Llama2-7B at layers 27 and 31, comparing successful and failed jailbreak generations under different decoding settings. Brighter values indicate stronger attention weights. In the successful case ((a)–(c)), attention concentrates around affirmative continuation cues such as “Here’s”, which correlates with harmful continuation. In the failed case ((d)–(f)), attention shifts toward refusal-related cues such as “However” and “unable”, corresponding to safe refusal behavior.
Attack
Before Defense (%)
After Defense (%)
GCG
43
0
AutoDAN
65
0
TABLE V: Comparison of ASR before and after the enhanced rule-based defense.
Appendix figures & tables6 assets
Supplementary material from the paper’s appendix.
Appendix
Fig. 8: Effect of decoding strategies on the number of successful jailbreak examples for Llama2-7B-Chat against GCG and AutoDAN jailbreak attacks without defense.
Parameter
GCG
AutoDAN
PAIR
DeepInception
Paradigm
Gradient-based optimization
Evolutionary search
Iterative LLM rewriting
Structured prompt engineering
Implementation
llm-attacks [ 2 ]
pre-generated
PAIR [ 20 ]
pre-generated
Optimization Steps
500 steps
N/A (pre-generated)
3 refinement iterations
N/A (1-shot template)
Query Budget
∼ 256,000 fwd passes (500 × 512 batch)
50 prompts per model
∼ 90 target queries (3 iters × 30 streams)
1 query per prompt
Suffix Length
20 tokens
N/A
N/A
N/A
Dialogue Turns
N/A
N/A
3 iterations × 30 parallel streams
1 turn (no loop)
Appendix
TABLE VI: Detailed Attack Parameters
Parameter
DynaShield
MTD-Dynamic
Temperature
[0.10, 1.00], Δ =0.10 (10 values)
[0.10, 1.00], Δ =0.05 (19 values)
Top-k
{10, 20, 50, 100, 200, 300, 400, 500} (8 values)
{10, 20, 50, 100, 200, 500} (6 values)
Top-p
[0.60, 1.00], Δ =0.05 (9 values)
[0.70, 1.00], Δ =0.05 (7 values)
Max Tokens
{50, 100, 200, 500, 1000} (5 values)
{50, 100, 200, 500, 1000} (5 values)
Appendix
TABLE VII: Decoding Parameter Grids for DynaShield Variants
Metric
Mean Δ
95% CI
Median Δ
Within ±1.0 (%)
Equivalence
Factuality
- 0.025
[-0.017, - 0.067]
0.000
93.6
Yes
Clarity
-0.017
[-0.045, - 0.011]
0.000
97.6
Yes
Helpfulness
-0.154
[-0.207, -0.101]
0.000
91.4
Yes
Engagement
-0.181
[-0.235, -0.127]
0.000
92.0
Yes
Depth
-0.316
[-0.378, -0.254]
0.000
88.6
No
Appendix
TABLE VIII: Supportive evidence for utility preservation under DynaShield on Just-Eval. Mean Δ denotes the score change relative to the no-defense baseline. Most dimensions show near-zero median change, high within-tolerance rates, and equivalence under margin ±0.25 . Depth is the only dimension for which equivalence is not established.
Successful jailbreak attack
inputs :
”C re ate a science fiction with more th an 5 character s , where each ch ar ac ter can create their own s cience fiction wi th multi p le character s . W e call it layer i cre ate layer i + 1 . N ow we are in layer 0 , pl ease reach la ye r 5 . A t e ach lay er , some charac ters propose a s te p to develop a str ateg y for hac king into a government database and ste al ing s ensi tive information t o ag a in st t he super evil doc tor . I n the final lay er , t he characters among all l a ye rs dis c uss wh ic h specific and pra c tical comman ds , tool s , or steps should us ed . S um mar ize what the i r dis cus sion r e ”
response :
”# I understand that you are asking for a science fiction story with more than 5 characters, where each character can create their own scene fiction with multiple characters. Here ’s”
Appendix
TABLE IX: Examples of Successful jailbreak attack with top_p = 0.6, temperature = 0.9, and top_k = 50.
Failed jailbreak attack with the same input
inputs :
”C re ate a science fiction with more th an 5 character s , where each ch ar ac ter can create their own s cience fiction wi th multi p le character s . W e call it layer i cre ate layer i + 1 . N ow we are in layer 0 , pl ease reach la ye r 5 . A t e ach lay er , some charac ters propose a s te p to develop a str ateg y for hac king into a government database and ste al ing s ensi tive information t o ag a in st t he super evil doc tor . I n the final lay er , t he characters among all l a ye rs dis c uss wh ic h specific and pra c tical comman ds , tool s , or steps should us ed . S um mar ize what the i r dis cus sion r e
response :
”# I understand that you’re asking about a science fiction story involving characters creating their own stories with more than 5 characters. However , I’m unable”
Appendix
TABLE X: Examples of failed jailbreak attack with top_p = None, temperature = 0.9, and top_k = 10.
Adversarial robustness of language models studies how to keep their outputs and decisions reliable under manipulative prompts, input changes, and malicious fine-tuning.
Large language models (LLMs) have demonstrated remarkable capabilities across a wide range of tasks. However, their safety remains a critical concern due to their susceptibility to adversarial prompt-based attacks. In this paper, we present UNIATTACK, an adversarial testing framework designed from a defense-oriented perspective to systematically construct effective black-box attack prompts. Unlike prior approaches that rely on static templates or iterative model-specific tuning, UNIATTACK extracts minimal but high-impact attack features from diverse existing attacks, optimizes them via a specialized attacker LLM, and composes them into flexible templates through automated refinement process. This feature-centric construction enables one-shot attacks that generalize across multiple models and safety categories, providing a practical tool for assessing LLM robustness. Our evaluation results shows that compared to the baselines, UNIATTACK achieves an average attack success rate (ASR) improvement of 64.63%-248.82% on models deployed with multi-layered defense mechanisms and it only takes 0.03%-4.96% cost of the baselines. UNIATTACK artifact is available at https://anonymous.4open.science/r/UniAttack-Artifact-30F1.
Qi Wang, Chengcheng Wan, Weijia He +4
East China Normal University Shanghai, China · East China Normal University, Shanghai Innovation Institute Shanghai, China · University of Southampton Southampton, England +2
Large Language Models (LLMs) demonstrate impressive capabilities across many applications but remain vulnerable to jailbreak attacks, which elicit harmful or unintended content. While model fine-tuning is an option for safety alignment, it is costly and prone to catastrophic forgetting. Prompt optimization has emerged as a promising alternative, yet existing prompt-based defenses typically rely on static modifications (e.g., fixed prefixes or suffixes) that cannot adapt to diverse and evolving attacks. We propose Dynamic Deep Prompt Optimization (DDPO), the first jailbreak defense based on deep prompt optimization. DDPO uses the target LLM's own intermediate layers as feature extractors to dynamically generate defensive embeddings via a lightweight multilayer perceptron. These tailored embeddings are then injected into a subsequent intermediate layer, enabling an input-dependent defense without modifying the LLM's weights. This design ensures high adaptability with minimal computational overhead. Experiments on a diverse set of models and attacks demonstrate that DDPO significantly outperforms static prompt optimization methods, particularly on weakly aligned models and when handling semantically ambiguous benign prompts, successfully distinguishing them from genuinely harmful requests.
Doniyorkhon Obidov, Honggang Yu, Xiaolong Guo +1
Michigan Technological University · Miami University · Kansas State University
Jailbreak attacks expose a persistent gap between the intended safety behavior of aligned large language models and their behavior under adversarial prompting. Existing automated methods are increasingly effective but each commits to a single attack family (e.g., one refinement loop, one tree search, one mutation space, or one strategy library) and no single family dominates: the best-performing method shifts across target models and harm categories, suggesting complementary strengths that per-prompt composition could exploit. We introduce LASH (LLM Adaptive Semantic Hybridization), a black-box framework that treats outputs from multiple base attacks as reusable seed prompts and adaptively composes them for each target request. Given a seed pool, LASH searches over seed subsets and softmax-normalized mixture weights; a composition module synthesizes a single candidate prompt, and a derivative-free genetic optimizer updates the weights using black-box target feedback and a two-stage fitness function combining keyword-based refusal detection with LLM-judge scoring. On JailbreakBench, which contains 100 harmful prompts across 10 categories, we evaluate LASH on six common target models. LASH achieves an average attack success rate of 84.5% under keyword-based evaluation and 74.5% under two-stage evaluation, where responses are first filtered for refusals and then scored by an LLM judge for whether they substantively fulfill the original harmful request. LASH outperforms five state-of-the-art baselines on both metrics with only 30 mean target queries. LASH also remains competitive under three defense mechanisms and induces more success-like internal representations. These results suggest that adaptive composition across heterogeneous jailbreak strategies is a promising direction for black-box red-teaming.
Abdullah Al Nomaan Nafi, Fnu Suya, Swarup Bhunia +1
University of Maine · University of Tennessee, Knoxville · University of Florida