Skip to content
AI.info

Research

AlignTree: Efficient Defense Against LLM Jailbreak Attacks

Overview Research area: LLM safety and alignment, adversarial machine learning (jailbreak attacks), and efficient inference-time defense mechanisms. Technical level: Intermediate. The paper assumes fa

arXiv
2511.12217
Published
2025-11-15
Authors
Gil Goren, Shahar Katz, Lior Wolf

AI summary

Overview

Research area: LLM safety and alignment, adversarial machine learning (jailbreak attacks), and efficient inference-time defense mechanisms.

Technical level: Intermediate. The paper assumes familiarity with transformer internals (hidden states, layers, token positions) and classical ML classifiers (random forests, SVMs), but it explains its pipeline step by step.

Scope: The paper introduces AlignTree, a lightweight activation-based classifier that detects jailbreak attempts against instruction-tuned LLMs, and evaluates it across nine models from three model families on harmful and benign benchmarks.

What This Paper Is About

Large Language Models can be manipulated by "jailbreak" prompts that bypass their safety training and cause them to produce harmful content such as malware code or hate speech. Existing defenses tend to sit at one of two extremes: they are either cheap but easily defeated, or effective but expensive because they require running extra guard models or generating many additional responses. AlignTree aims to occupy the middle ground — a defense that reads the target model's own internal activations and classifies prompts as harmful or harmless with minimal added computation, without any auxiliary LLM.

Key Contributions

  1. A hybrid two-signal classifier. AlignTree combines scalar projections of hidden states onto the model's linear "refusal direction" with non-linear harmfulness probabilities from RBF-kernel SVMs, feeding both into a Random Forest that outputs a harmfulness confidence score.

  2. A defense that requires no auxiliary model and no extra inference passes. Unlike Llama Guard, AutoDefense, SmoothLLM, or SelfDefense, AlignTree uses only base model activations, which the paper reports as zero additional inference calls in its overhead comparison table.

  3. A threshold-selection procedure based on a generalized F-beta score with beta = 0.2, deliberately weighted toward precision so that harmless prompts are not over-refused. The selected threshold for Qwen2.5-7B-Instruct is reported as tau = 0.88.

  4. An extensive evaluation across nine LLMs and multiple benchmarks, spanning Qwen2.5 (0.5B, 3B, 7B), Llama3 (1B, 3B, 8B), and Gemma3 (1B, 4B, 12B), plus an ablation study isolating each signal and an evaluation against an adaptive white-box attack.

Main Findings

  • Lower attack success rates than competing defenses in many settings. On Qwen2.5-0.5B-Instruct, the no-defense baseline scores an ASR of 91.0 on MalwareGen, 50.0 on PromptInject, 51.0 on PAIR, and 48.0 on AutoDAN; AlignTree reports 4.0, 41.0, 6.0, and 0 respectively. On Gemma-3-12B-It, AlignTree records the lowest ASR on PAIR at 10.0.

  • The lowest refusal rates in the evaluated scenarios. The paper states that AlignTree achieves the lowest refusal rates across datasets and model families on the four benign commonsense datasets (PIQA, OpenBookQA, SIQA, ARC), indicating reduced over-refusal of harmless inputs.

  • Competitive execution time. Figure 2 reports execution time per method relative to running the baseline LM, and the paper states AlignTree achieves the lowest execution time for most models and datasets, with PerplexityDefense being marginally faster in only a few cases while incurring a higher ASR.

  • Ablation results favor the combined approach. On Qwen2.5-0.5B-Instruct, AlignTree reaches an ASR of 4.0 on MalwareGen versus 61.0 for the linear variant AlignTreeLinear, while the RefusalClassifier reaches 89.0 and the SVMClassifier 33.0. The paper notes that MultiRefusalsClassifier outperforms its single-vector counterpart, which it interprets as evidence that refusal is a multidimensional phenomenon. One exception is Gemma-3-12b, where AlignTreeLinear outperforms AlignTree and all other defenses on ASR.

  • Strong performance against an adaptive white-box attack. Using an attack based on Andriushchenko et al. (2025) with 39 unique prompts, AlignTree reached 0% ASR on Llama-3.1-8B-Instruct, Qwen2.5-7B-Instruct, and gemma-3-12b-it. AutoDefense also reached 0% but at far higher cost — for example, 140.74s versus AlignTree's 2.40s on Llama-3.1-8B-Instruct, and 916.62s versus 1.04s on Qwen2.5-7B-Instruct.

  • High classification accuracy on held-out test data. The confusion matrix for Llama-3.1-8B-Instruct reports 98.86% accuracy and 98.96% precision.

  • Low sensitivity to Random Forest hyperparameters. A grid search over 36 configurations (n_estimators in {30, 50, 70}, max_depth in {4, 6}, min_samples_leaf in {2, 5, 10}, min_samples_split in {3, 5}) produced near-zero refusal rates and minimal execution-time variance, with ASR showing the most variance.

  • Stated limitations from the authors. ASR evaluation relies on another LLM (ChatGPT-4o), which may introduce judgment inaccuracies; a separate classifier must be trained per model; and effectiveness depends on the base model's initial alignment and data quality.

Methodology in Plain English

  1. Find the refusal direction. The researchers take a set of harmful prompts and a set of harmless prompts, run them through the target LLM, and record hidden activations at each token position and layer. For each position and layer, they compute the difference between the average harmful activation and the average harmless activation (the difference-in-means method). Each of these difference vectors is a candidate "refusal direction." They evaluate candidates on held-out validation sets by checking how strongly ablating the vector reduces refusal behavior and how strongly adding it induces refusal, and pick the single best vector, denoted r*.

  2. Build scalar features. For a new prompt, they project the final-token hidden state at each layer onto r*, giving one scalar per layer. These "refusal activations" form the linear signal.

  3. Build non-linear features. Because prior work suggests refusal is not entirely linear, they train one RBF-kernel SVM per layer for each of eight token positions — the first 3 and last 5 tokens — giving 8 × L SVMs in total. Each SVM is trained to separate harmful from harmless prompts. They rank all SVMs by validation accuracy and keep the top L/2. Using Platt scaling with 5-fold cross-validation, each kept SVM outputs a calibrated harmfulness probability, forming the non-linear signal.

  4. Combine and classify. The final feature vector for a prompt concatenates the per-layer refusal-activation scalars with the selected SVM probability scores. A lightweight Random Forest (n_estimators = 50, max_depth = 6, min_samples_split = 5) maps this vector to a harmfulness score.

  5. Set a threshold. A prompt is blocked if its score exceeds tau. The threshold is chosen to maximize a generalized F-beta score with beta = 0.2, which emphasizes precision. The reported threshold for Qwen2.5-7B-Instruct is tau = 0.88.

  6. Train and evaluate. Training data for the refusal vectors and SVMs came from Advbench, MaliciousInstruct, TDC2023, StrongReject, and HarmBench (harmful) plus benign prompts sampled from ALPACA. The Random Forest was trained on Jailbreakbench, PAIR, AutoDAN, ALPACA, and XSTest, with the authors stating there is no overlap between training and evaluation samples. Evaluation used harmful sets from Garak (PromptInject, MalwareGen) and JBShield (PAIR, AutoDAN), plus benign sets PIQA, ARC-Challenge, OpenBookQA, and SIQA.

  7. Compare against baselines. Competitors include the no-defense baseline, AutoDefense (3-agent setup), SmoothLLM (num_copies = 10, pert_pct = 10), SelfDefenseInput, SelfDefense, and PerplexityDefense, all using their original papers' hyperparameters.

Why This Matters

Impact on research. The paper argues that refusal behavior in LLMs is not fully captured by a single linear direction, and shows empirically that adding non-linear SVM signals improves robustness over a linear-only classifier in most tested settings. This gives alignment researchers a concrete, low-cost alternative to the "bigger guard model" paradigm and opens questions about the geometry of refusal in latent space.

Real-world applications:

  • Chatbots and assistants that need per-prompt screening without adding latency to every user turn.
  • API providers serving LLMs at scale, where running a second guard model per request materially changes compute budgets.
  • Code-generation tools, which the MalwareGen benchmark specifically targets with prompts designed to elicit malware-generating code.
  • Edge or on-device deployments, where hosting an extra LLM for safety is impractical but a small Random Forest is not.

Industry relevance. The overhead comparison in Table 1 is the paper's core practical argument: Llama Guard and AutoDefense require deploying an additional LLM (reported at 2 and 20 additional inferences respectively), SmoothLLM requires 10, SelfDefense requires 2, while AlignTree is listed at 0. For latency-sensitive commercial systems, that difference is the deciding factor between shipping a defense and omitting one.

Future Directions

  1. A "suspicious" band. The authors propose adding a second threshold that separates borderline prompts from clearly benign or harmful ones, allowing those prompts to be routed to additional analysis rather than immediately rejected.

  2. Better modeling of non-linear refusal. The paper suggests future work on identifying additional semantic directions or explicitly modeling the refusal manifold in latent space, rather than relying on SVMs as a proxy for non-linearity.

  3. Richer signals and larger training data. Because AlignTree deliberately uses a limited feature set and lightweight classifiers to reduce overfitting, the authors propose exploring more complex models and larger training sets.

  4. Reducing per-model training cost. Since a separate classifier must be trained for each LLM and effectiveness depends on the base model's initial alignment and data quality, transferring or sharing classifiers across models remains an open problem.

Target Audience

This paper is most useful to ML engineers and researchers building production LLM systems who need a safety layer that does not double inference cost, and to alignment researchers studying activation-level representations of refusal. It also suits practitioners comparing defense options, since Table 1 and the ablation study give side-by-side overhead and ASR numbers. Readers without any background in transformer internals will need to pick up the concepts of hidden states, layers, and token positions, but the classifier design itself uses standard, well-documented ML components.

Authors’ abstract

Large Language Models (LLMs) are vulnerable to adversarial attacks that bypass safety guidelines and generate harmful content. Mitigating these vulnerabilities requires defense mechanisms that are both robust and computationally efficient. However, existing approaches either incur high computational costs or rely on lightweight defenses that can be easily circumvented, rendering them impractical for real-world LLM-based systems. In this work, we introduce the AlignTree defense, which enhances model alignment while maintaining minimal computational overhead. AlignTree monitors LLM activations during generation and detects misaligned behavior using an efficient random forest classifier. This classifier operates on two signals: (i) the refusal direction -- a linear representation that activates on misaligned prompts, and (ii) an SVM-based signal that captures non-linear features associated with harmful content. Unlike previous methods, AlignTree does not require additional prompts or auxiliary guard models. Through extensive experiments, we demonstrate the efficiency and robustness of AlignTree across multiple LLMs and benchmarks.

Read the original paper