Manuscript Offprint

arXiv:2610.22723

LEMON: Equivariant Learning over Attention Maps for Zero-Shot Misbehavior Monitoring on New LLMs

Guy Bar-Shalom, Mor Geva, Fabrizio Frasca, Haggai Maron

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Large language models exhibit misbehaviors that hinder deployment in high-stakes settings. One approach to monitor such failures is to use an external LLM as a monitor, but this is prohibitively expensive. A well-known and efficient class of monitors can detect such failures from internal representations (such as activation probes), but are tied to the model they were trained on, requiring costly re-annotation as new LLMs appear. A natural way to avoid this repeated annotation cost is to develop internal-representation based monitors that transfer zero-shot across LLMs. However, such transfer is challenging because internal representations are not naturally aligned across models; in particular, attention maps, known to contain signals of misbehavior, may differ in head function, ordering, and model depth. In this work, we characterize those cross-model attention mismatches as algebraic symmetries and use geometric deep learning principles to build LEMON (Language-model Equivariant MONitoring Network) an online graph neural network-based monitor, whose predictions are invariant under these symmetries. LEMON processes attention maps token-by-token, as they are produced and outputs a score after every token (or every window of W tokens) at negligible cost. Across 16 LLMs and six datasets, in the zero-shot cross-model setting, LEMON outperforms all baselines on both hallucination and jailbreak monitoring tasks, improving over the strongest by up to 14 ROC-AUC points. 1^{1}

Same signal, different coordinates

Figure

Our architecture: LEMON

the signal can sit at a different L×HL \times H coordinate in each LLM

⇒\Rightarrow mismatch group W=SH∖CL\mathcal{W} = \mathcal{S}_H \setminus \mathcal{C}_L

Figure

W-equivariant message passing

Online monitoring an unseen LLM

Figure

no labels from the unseen LLM;

the error is flagged

while generating

Figure 1: Our framework for zero-shot monitoring of misbehavior across LLMs. (left) The attention map A∈[0,1]N×N×L×H\mathbf{A} \in [0,1]^{N \times N \times L \times H} is a stack of attention maps indexed by (layer, head). (middle) LEMON operates on a structured, attributed graph constructed from the attention maps and applies W-equivariant message passing. (right) LEMON can flag misbehavior during generation.

∗^{*}Equal supervision.

1^{1}Code will be released soon.

1 Introduction

Despite their impressive capabilities, LLMs are known to exhibit undesirable behaviors: they may memorize training data (Carlini et al., 2021; Nasr et al., 2023), hallucinate responses (Pagnoni et al., 2021; Cao et al., 2022; Qiu et al., 2023), fall prey to flawed reasoning (Song et al., 2026), and be jailbroken (Wei et al., 2023; Zou et al., 2023), i.e., persuaded to generate harmful or otherwise restricted content. As LLMs find growing use in high-stakes domains, developing lightweight, online 2^{2} monitors that flag potential misbehavior on-the-fly becomes increasingly important.

Misbehaviors can be monitored with separate, capable LLMs acting as judges: they can process the provided prompt, along with the generated response to assess whether a specific misbehavior has occurred (Manakul et al., 2023; Souly et al., 2024; Mazeika et al., 2024). This approach is, however, fundamentally incompatible with online applications due to its prohibitive computational cost incurred by the additionally required LLM executions. A complementary and more agile class of monitors leverage instead the internal signals of the target LLM itself (Azaria & Mitchell, 2023; Kramár et al., 2026): data such as hidden representations, attention maps, output token log-probabilities. A pioneering example is that of probing classifiers (Belinkov, 2022), which train logistic regression models over activations to detect, e.g., the presence of the high-level concept of incorrectness. More recent approaches have generalized this idea by learning from more holistic views of the model's internal computation and developing tailored architectures to process them Bar-Shalom et al. (2025); Frasca et al. (2026); Samuel et al. (2026). With their low latency, these approaches are fundamentally more suitable to monitor the generation process on the fly. The best performing methods in this class, however, typically require access to annotated training datasets to estimate their parameters. This represents a limiting factor preventing their immediate application to newly released LLMs, as each requires curating new misbehavior datasets and monitor retraining.

Encouragingly, evidence suggests that internal representations preserve a similar underlying structure across models, differing primarily in the coordinates used to encode it. For example, (Huh et al., 2024; Morcos et al., 2018; Moschella et al., 2022) showed that the activation spaces of different models capture similar semantic information and can even be related through linear transformations. Likewise, (Ivanitskiy et al., 2025; Elhelo & Geva, 2025) found recurring patterns in attention maps across models, although, potentially, at distinct layer-head locations. These observations motivate the main question we tackle in this paper: “Can we develop a learnable monitor capturing shared, model-agnostic, features from attention maps that are predictive for misbehaviors?”

In this paper, we first demonstrate, through a concrete example of hallucination detection (see Figure 2), that a well-known attention-based heuristic score (Chuang et al., 2024) shows essentially no correlation across corresponding layers and heads across different models. We then show that these mismatches can be characterized by algebraic symmetries of multi-head attention. These correspond to transformations of the attention maps that change them while leaving the overall attention function unchanged. We argue that these should, therefore, be treated equivalently by the processing architecture, i.e., that we should design an invariant monitor. We formally characterize these symmetries, which intuitively correspond to independently permuting the attention heads within each layer of the model, while also accounting for shifts (translations) of the layers themselves 3^{3}. Motivated by prior work (Frasca et al., 2026), we formulate training a misbehavior monitor as a learning problem over an attention-induced directed graph, which we propose to endow with (L×H)(L \times H)-structured attention scores as node and edge features, subject to the symmetries highlighted

2^{2}Throughout, online monitoring means producing a score after each token (or each window of W tokens) during generation.

3^{3}The resulting symmetry group is the wreath product SH≀CLS_H \wr C_L, where SHS_H captures independent permutations of the HH heads within each of the LL layers, and CLC_L acts by cyclically permuting the layers.

above. We hence develop LEMON (Language-model Equivariant MONitoring Network), a graph neural network architecture designed to be invariant to these symmetries, thereby explicitly agnostic to cross-model mismatches and hence directly applicable to unseen LLMs in a zero-shot fashion (see Figure 1).

LEMON is evaluated comprehensively on two monitoring tasks, hallucination and jailbreak detection, across 16 LLMs and six datasets. In this zero-shot setting, LEMON substantially outperforms baselines while remaining extremely lightweight: it introduces less than 8% total overhead relative to standard generation. Moreover, LEMON operates online, allowing to halt a response mid-generation, so that a misbehavior can be detected before completion. We formalize this setting of selective generation along with token-level coverage and risk metrics, and show that it offers a useful trade-off between abstaining from generation and reducing error rates.

Contributions. (1) We characterize a class of algebraic symmetries in multi-head attention that induce layer-head mismatches across models. (2) We introduce LEMON, a symmetry-aware monitor that transfers zero-shot to unseen LLMs. (3) LEMON operates online, enabling selective generation with less than 8% overhead. (4) Across 16 LLMs and six datasets on hallucination and jailbreak detection, LEMON consistently outperforms prior baselines.

References (84)