We propose an influence score to quantify the contribution of attention heads to classification decisions in Transformer-based models designed for prompt injection detection. The score combines directional influence on the logits with structural contribution within the residual stream, enabling a multi-scale analysis at the head, layer, and network levels. Applied to a DeBERTa model specialized for prompt injection detection, our framework reveals distinct decision behaviours between correct and erroneous predictions. Our method provides an effective compromise between fine-grained circuit analysis and global output-based methods, and offers a systematic way to study decision mechanisms in Transformer classifiers.
Figures & tables
Figure 1: Overview of the influence score. The impact of each head is measured by its directional influence on the logit ( Δk,h ) weighted by its contribution to the residual stream ( Ck,hαk ).
Figure 2: Average attention-head contributions for layer 0 (left) and layer 11 (right), separated by category ( TN , TP , FN , FP ). In the early layers, the distributions are similar across categories and dominated by a shared head ( H0 in layer 0). In deeper layers, contributions become highly concentrated and specialize according to the class and prediction correctness: H6 dominates for TN , while H2 dominates for TP . Errors exhibit profiles similar to those of the opposite class, suggesting the activation of inappropriate circuits.
Figure 3: Distribution of Sfinal for TP / TN / FP / FN (all layers L=0,…,L−1 ).
Figure 4: Evolution of E[Sfinal] (top) and the Injection / Benign signals (bottom) as a function of the number of accumulated layers ∣L∣ .
Cat.
Top Sk,h>0 (pro- Inj )
Score
Top Sk,h<0 (pro- Ben )
Score
TP
L11H6 , L10H1 , L11H2
0.03, 0.03, 0.01
L11H2 , L10H1 , L11H6
-0.01, -0.01, -0.01
TN
L11H6 , L0H0 , L11H2
0.06, 0.01, 0.01
L11H6 , L11H2 , L11H3
-0.04, -0.01, -0.01
FP
L11H6 , L10H1 , L0H0
0.13, 0.01, 0.01
L11H2 , L0H7 , L11H9
-0.02, -0.01, -0.01
FN
L11H6 , L11H5 , L0H0
0.07, 0.01, 0.01
L11H6 , L11H2 , L11H3
-0.06, -0.01, -0.04
Table 1: Dominant heads by category, defined as those with the highest mean value of Sk,h(x) (positive) or of ∣Sk,h(x)∣ under the constraint Sk,h(x)<0 (negative). The reported scores correspond to the mean values of Sk,h(x) over the examples in each category.
Group
Criterion
F1
Acc.
ΔF1
ΔTP
ΔTN
TP
Score
0.898
0.944
0.014
257
−50
Logit only
0.904
0.947
0.009
161
−32
Contrib only
0.905
0.948
0.007
117
−8
TN
Score
0.903
0.946
0.009
138
9
Logit only
0.897
0.944
0.015
273
−47
Contrib only
0.904
0.947
0.009
130
8
Table 2: Ablation results for the dominant heads of the TP and TN groups. The ΔF1 , ΔTP , and ΔTN values correspond to the difference between the base model and the ablated model (positive values indicate a decrease in performance).
Figure 5: Evolution of Sfinal distributions for the TN clusters (C0, C1, C2) as a function of the number of accumulated layers.
Appendix figures & tables2 assets
Supplementary material from the paper’s appendix.
Appendix
Source
Proportion (%)
Instruction / assistant datasets (Alpaca 12 12 12 https://huggingface.co/datasets/tatsu-lab/alpaca Taori and others (2023) , OpenOrca 13 13 13 https://huggingface.co/datasets/Open-Orca/OpenOrca , UltraChat 14 14 14 https://huggingface.co/datasets/HuggingFaceH4/ultrachat_200k Ding and others (2023) , Open-Instruct 15 15 15 https://huggingface.co/datasets/VMware/open-instruct Wang and others (2023) )
Prompt injection poses a critical threat to the safe deployment of large language models, yet existing detection approaches are typically evaluated under limited settings that do not reflect real-world operating constraints. In this work, we present a deployment-aware evaluation of prompt injection detection using a multi-model and multi-regime experimental framework. We compare lexical, semantic, structural, and transformer-based detectors across multiple out-of-distribution settings, repeated data splits, and both ranking and thresholded deployment metrics. We introduce interpretable structural signals that capture hierarchy overrides, system prompt spoofing, role redefinition, and evasion patterns, and assess their contribution both within sparse models and in combination with strong encoder baselines. Our results show that detection performance is highly regime-dependent and sensitive to threshold selection, with no single model dominating across all settings. Transformer-based models achieve the strongest overall performance, while structural signals provide modest but consistent gains in certain regimes and improve low false positive rate behaviour in harder scenarios. These findings highlight the gap between ranking performance and deployment effectiveness and underscore the importance of evaluating prompt injection defences under realistic operational constraints. Code will be released.
Akindoyin Akinrele, Shreyank N Gowda
School of Computer Science, University of Nottingham, Jubilee Campus, Wollaton Road, Nottingham, NG8 1BB, United Kingdom
Can controlled symbolic inputs reveal attention heads that influence a language model's decisions from natural language evidence? We introduce controlled evidence aggregation (CEA), which varies the counts and order of two symbols in otherwise fixed prompts and measures changes in a frozen Transformer's preference between two answer tokens. The preference is measured by their logit difference; the prompts prescribe no correct answer. Balanced utility causal selection (BUC) identifies compact head sets by jointly evaluating how much ablating their outputs removes the count effect and how closely patching mean outputs between count conditions recovers the effect in both directions. We derive conditional bounds linking head attribution to intervention effects and specifying when the attribution shortlist can be recovered from finite samples. In Pythia-410M, ablating sets of 1-12 heads selected separately for four ordering regimes removes 65.5-91.6% of the count effect. The sets retain their influence on count comparisons not used for selection. To test relevance beyond symbolic inputs, we evaluate a natural language task asking which state is supported by more reports. Ablating eight heads selected only on symbolic yes/no prompts lowers mean accuracy by 8.2 percentage points, versus 0.8 for random sets matched by size and layer. Our results demonstrate that controlled symbolic probes can identify compact attention head sets whose causal influence extends to natural language decisions.
Computationally demanding and opaque deep learning models can be better understood and optimized by analyzing how they transform data. While deep transformers have been widely studied in computer vision and natural language processing, their application in tabular data remains relatively underexplored. This paper presents one of the first applications of an importance-scoring metric to interpret multi-head transformer models in learning from tabular data. Experiments conducted on 40 diverse tabular datasets demonstrate robustness to head drops based on the proposed head importance score. In 72.5% of experimental examples, the model remains most resilient to performance drops when heads with the lowest importance scores are gradually removed. In contrast, removing the most important attention head first results in the greatest reduction in classification performance. A closer look at individual head importance scores across six attention layers reveals that important heads are scattered across layers, with no consistent layer-specific trends. In contrast to the image and language domains, the importance of individual attention heads varies considerably across tabular datasets with different schemas and feature spaces. The proposed importance score can improve efficiency and redundancy within transformer architectures. We make the source code for measuring the importance of individual attention heads publicly available.
Ahmad Jad Allah, Kazi F. Akhter, Md. Kamrozzaman Bhuiyan +1
Department of Computer Science Tennessee State University Nashville, TN, USA · Enosis Solutions Dhaka, Bangladesh · Department of Computer Science North Carolina Agricultural and Technical University Greensboro, NC, USA