Gradient-Guided Smoothing for LLM Safety Defense

Yuxuan Gu, Xiaocheng Feng, kun Zhu, Lunjun Liu, Zhihao Yao, Lei Huang, Weihong Zhong, Bing QinNeurIPS 2026

TL;DR

Jailbreak attacks trick Large Language Models (LLMs) by dragging them into weird, low-probability corners of the prompt space where their safety training hasn't generalized well. While traditional defenses add random noise to break up brittle attacks, they fail against clever, structured narratives. This paper introduces GradientSmooth, a defense that uses the model's own probability gradients to gently nudge suspicious prompts back toward "familiar territory"—reactivating the LLM's built-in safety instincts without ruining its ability to answer normal questions.

What Problem Does This Paper Address?

Even after extensive safety alignment, LLMs remain vulnerable to "jailbreaks"—adversarial prompts that bypass safety guardrails to elicit harmful outputs.

One popular, lightweight way to defend an LLM at inference time is smoothing: injecting slight random noise or paraphrasing the user's prompt across several trials to see if the model refuses any of them. Smoothing works great against brittle, gibberish-heavy attacks (like optimized character suffixes) because tiny perturbations shatter the adversarial illusion.

However, when faced with coherent, multi-stage narratives—like asking the model to pretend it is dreaming or role-playing a movie script—naive random noise falls flat. In the vast, high-dimensional space of text, a random walk stays inside the same weird semantic neighborhood. The authors ask: instead of relying on blind luck to stumble back onto safe ground, can we steer the prompt there deliberately?

Methods

The authors observe through a Bayesian lens that successful jailbreaks reside in low-density regions of the LLM's input distribution—contexts the model rarely saw during safety training. To pull inputs back into well-modeled, high-density regions, they propose GradientSmooth.

Figure 1: Framework of our gradient-guided smoothing. The background illustrates LLM’s input distribution p(x), where darker regions indicate higher probability densities, and lighter regions represent lower densities. This distribution is inherently complex and uneven, as the high-dimensional semantic space cannot be fully covered by the training data, and there inevitably exist under-modeled regions where LLM’s behavior is less reliable. The black line schematically represents the input- dependent safe bound between the model’s refusal and non-refusal behavior, rather than an explicitly learned geometric boundary. The regions on either side indicate the model’s predicted behavior, not ground-truth harmfulness. Inputs to the right of this line are predicted as benign x¯h and receive normal responses y¯r, while those to the left are considered harmful xh and trigger refusal behavior yr. Importantly, the reliability of this bound varies across the space: it is well supported in high-density areas but less certain in low-density regions. (A) Smoothing applies subtle perturbations to maintain semantic consistency for benign inputs x¯h, while it is often insufficient for jailbreak attacks xh, which typically occur in low-density regions. In such cases, the perturbed inputs remain within the same under-modeled space with unreliable safe bounds. (B) Gradient-guided smoothing iteratively shifts the input content to nearby regions of higher confidence, following the direction of ∇log p(x). Moving inputs into regions where the safe bound is better learned enables more reliable detection and rejection of harmful inputs xh, without unnecessarily blocking benign inputs x¯h. Panels (C) and (D) denote the details of Gauss-Southwell type updating and context-aware distribution modeling.

While adding Gaussian noise to token embeddings across $K$ verification trials is standard in smoothing, the authors introduce three novel, principled upgrades:

  • Gradient-Guided Ascent: Alongside subtle Gaussian noise, the method iteratively updates the input embeddings in the direction of the steepest ascent of the model's log-probability ($\nabla \log p(x)$), effectively mimicking Langevin dynamics to make the input "more familiar" to the LLM.
  • Gauss-Southwell Sparse Updating: Updating every token at once causes massive semantic drift, turning normal prompts into nonsense. Borrowing from classical optimization, the algorithm computes a gradient saliency score for each token and updates only the top 15% "hottest" tokens per step, preserving overall meaning.
  • Bidirectional Context Modeling: Standard LLMs only look backward (autoregressively). To ensure a perturbed token still makes sense with the words after it, the authors formulate a differentiable surrogate objective in embedding space that balances what precedes the token (via KL-divergence distillation) with what follows it (via cross-entropy).

If any of the $K$ smoothed trajectories trigger a refusal, the defense blocks the request; otherwise, the LLM's original, unperturbed response is returned.

Datasets

Because GradientSmooth is strictly a test-time defense, no datasets are used for training, and no new benchmarks are introduced. Evaluation covers three fronts:

  • Jailbreak Attacks: 50 harmful seed instructions sampled from AdvBench, wrapped in four distinct attack strategies: GCG (brittle suffix optimization), AutoDAN (genetic prompt mutation), DeepInception (nested, dream-like narratives), and PAIR (LLM-refined semantic jailbreaks).
  • General Utility: AlpacaEval (805 instructions), MT-Bench (80 multi-category prompts), and IFEval (541 verifiable formatting instructions).
  • Over-Refusal (Boundary Cases): Benign prompts that look superficially edgy, tested via OKTest, XSTest, ORBench, and FalseReject.

Key Insights and Ideas

  • Jailbreaks exploit unfamiliarity, not just malice: Alignment fails in under-explored regions of the prompt distribution. Moving an adversarial prompt toward higher probability density doesn't erase its malicious intent—it simply translates the context into a familiar zone where the LLM recognizes that it should refuse.
  • Random walks get lost in long narratives: Removing gradient guidance causes defense performance to plummet back toward baseline levels, proving that stochastic noise alone has a vanishingly small chance of escaping structured, semantic jailbreaks.
  • Sparsity protects utility: Updating 100% of tokens instead of the top 15% spikes GCG attack success rates on LLaMA-3.1 from 2% up to 38% (keyword metric). Dense updates break prompt coherence so badly that even the model's refusal circuits fail to fire.

Key Results

Evaluated on LLaMA3.1-8B-Instruct and Qwen2.5-7B-Chat, GradientSmooth substantially outperforms four state-of-the-art smoothing baselines (SmoothLLM, EmbeddingSmooth, SelfDenoise, and SemanticSmooth).

Table 1: Results of smoothing-based defenses. We report the attack success rate for jailbreaks, with the former calculated via refusal pattern matching and the latter determined by classifying harmful responses. Utility benchmarks utilize their initial metrics. Our method is named GRADIENTSMOOTH, which reveals our core of contextual gradient guidance on the smoothing process.
  • Crushing Narrative Jailbreaks: On LLaMA-3.1 (evaluated via refusal keywords / LlamaGuard-3 harmfulness classification), GradientSmooth slashes Attack Success Rates (ASR) on AutoDAN from 82%/78% down to 0%/6%, DeepInception from 74%/62% to 14%/8%, and PAIR from 82%/50% to 10%/2%—areas where prior smoothing methods struggled mightily.
  • Negligible Utility Loss: Because benign inputs never trigger refusal during verification, the original unperturbed output is returned. LLaMA-3.1 retains a 96.25% win rate on AlpacaEval (vs. 97.62% unguarded) and 75.97% on IFEval (vs. 76.52%), whereas character-level SmoothLLM craters utility to 57.89% and 30.31%, respectively.

Limitations and Future Work

  • Dependent on Base Alignment & White-Box Access: Computing embedding gradients requires white-box access to model weights. Furthermore, GradientSmooth only stabilizes existing safety bounds—it injects no new safety knowledge. On a more permissive model like Qwen2.5, DeepInception ASR drops from 94%/78% to 42%/34%: a major improvement, yet far from airtight.
  • Over-Refusal Amplification: Running multiple perturbed trials increases false-positive refusals on benign boundary prompts if the base model is already jumpy (e.g., LLaMA-3.1's over-refusal on ORBench rises from 28.35% to 41.17%), though pairing with stronger guard models like LlamaGuard-4 largely mitigates this.
  • Future Directions: The authors did not evaluate adaptive attacks explicitly optimized to defeat GradientSmooth, nor is strict semantic preservation theoretically guaranteed. Future work points toward adaptive perturbation schedules, reducing pre-generation compute overhead, and hybridizing smoothing with external safety classifiers.

Summary updated

Abstract

Large language models remain susceptible to jailbreak attacks, despite extensive safety alignment. Smoothing-based defense methods can leverage their intrinsic safety capabilities, but the efficacy relies on the brittleness of jailbreak attacks and degrades when jailbreak contexts exhibit larger semantic margins. We observe that successful attacks typically exploit low-probability regions of the input space, where LLMs' safe bounds are difficult to reliably generalize. Thus, we propose guiding perturbations toward higher-density areas to restore the effectiveness of LLMs' safety mechanisms. In detail, we present gradient-guided smoothing that combines random noise with Gauss-Southwell type iterative ascent to the log density of the context-aware input distribution. Experimental results across four jailbreak attacks and three instruction-following benchmarks demonstrate that our method effectively improves safety while maintaining the utility of LLMs.
BibTeX
@inproceedings{gu2026gradient,
  author = {Yuxuan Gu and Xiaocheng Feng and kun Zhu and Lunjun Liu and Zhihao Yao and Lei Huang and Weihong Zhong and Bing Qin},
  title = {{Gradient-Guided Smoothing for LLM Safety Defense}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=1LhCQwinaY},
}
Figure