SafeSpec: Fast and Safe LLM via Dynamic Reflective Sampling

Haotian Xu, Zeyang Zhang, Linbao Li, Huadi Zheng, Yu Li +1 more
6/18/2026
cs.CRcs.AI

No confident code implementation found for this paper.

Abstract

Speculative inference accelerates large language model (LLM) decoding but provides no inherent safety guarantees. Existing safety defenses are largely incompatible with speculative inference: they either introduce additional computation or disrupt the draft-verify mechanism, negating acceleration benefits.

Show full abstract

This reveals a fundamental incompatibility between current safety methods and speculative decoding. We propose SafeSpec, a safety-aware speculative inference framework that integrates risk estimation directly into the verification process. SafeSpec attaches a lightweight latent safety head to the target model to jointly evaluate semantic validity and safety in a single forward pass. When unsafe generations are detected, SafeSpec applies rollback and safety-guided reflective multi-sampling to recover safe continuations rather than terminating generation. We model jailbreak attacks as distributional shifts over generative trajectories, where adversarial prompts increase the probability of harmful continuations without eliminating safe ones. Under this model, SafeSpec performs risk-aware trajectory recovery within the speculative decoding process. Across multiple models and adversarial benchmarks, SafeSpec achieves a substantially improved safety-efficiency trade-off. On Qwen3-32B, SafeSpec reduces attack success rates by 15% while preserving a 2.06x inference speedup on benign workloads, demonstrating that speculative acceleration and inference-time safety can be jointly optimized.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{xu2026safespec,
  title  = {SafeSpec: Fast and Safe LLM via Dynamic Reflective Sampling},
  author = {Haotian Xu and Zeyang Zhang and Linbao Li and Huadi Zheng and Yu Li and Cheng Zhuo},
  year   = {2026},
  eprint = {2606.19755},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2606.19755v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2606.19755.svg)](https://codeofpaper.com/paper/2606.19755)

Discussion