Reproduce “HSF: Defending against Jailbreak Attacks with Hidden State Filtering” on OpenResearch

Run Claude Code, Codex or any coding agent as a research agent: literature, hypotheses and experiments on your laptop, cluster or cloud GPUs.

Universal app for Apple silicon and Intel. Requires macOS 11 or later.

About this paper

Cheng Qian, Hainan Zhang, Lei Sha, Zhiming Zheng

Researchers at Beihang University and Peking University developed Hidden State Filtering (HSF), a pre-inference defense mechanism that identifies and blocks jailbreak attacks against Large Language Models. HSF trains a lightweight classifier on the LLM's hidden state representations, significantly reducing attack success rates to near 0% for strongly aligned models while maintaining high accuracy for benign queries and incurring negligible computational overhead.

Key insights

  • Aligned Large Language Models (LLMs) inherently develop internal hidden state representations that allow them to distinguish between benign, harmful, and jailbreak queries.
  • Leveraging these hidden states for pre-inference classification enables highly efficient and effective defense against adversarial attacks without incurring significant computational overhead.
  • A lightweight Multilayer Perceptron (MLP) trained on concatenated hidden state vectors from the LLM's final decoder layer can accurately identify malicious input intent.

Summary by alphaXiv.

Tip: change arxiv.org to autoarxiv.org in any arXiv abstract link to open the paper here.