To catch LLM misbehavior (hallucinations, jailbreaks) as it happens, a monitor must be online, scoring the text while it is generated, and lightweight, adding little to the cost of generation. Monitors that read the LLM's own internals (in particular, attention maps, as considered in this paper) typically meet both requirements, but each is trained for one specific LLM, and every newly released LLM needs new annotations in order to train a new monitor.
Ideally, we want a single monitor that transfers zero-shot to unseen LLMs. That is hard: attention maps carry misbehavior signals, but heads with the same role sit at different positions in different models:
Heads. A multi-head attention layer concatenates its head outputs and applies an output projection \(\mathbf{W}^{O}\). Permuting the head outputs and the corresponding row blocks of \(\mathbf{W}^{O}\) leaves the layer's output unchanged:
Here \(\textcolor{#ad0000}{\mathbf{P}_\sigma}\) is the block-permutation matrix corresponding to the head permutation \(\textcolor{#ad0000}{\sigma} \in \mathcal{S}_H\). So two LLMs can implement the same head in different slots; see the illustration below of this symmetry for a single layer.
Layers. Layers are composed sequentially, so their order matters. Their absolute indices, however, carry no fixed meaning across models of different depths. We model layer relabelings as cyclic shifts \(\pi \in \mathcal{C}_L\), treating them as an approximate symmetry assumption that reduces dependence on absolute layer indices.
Together, an independent head permutation in every layer plus a layer shift form the group \(\mathcal{W} = \mathcal{S}_H \wr \mathcal{C}_L\). The relabeling is \((\ell,h) \mapsto (\pi(\ell),\sigma_\ell(h))\), so the group action is as follows:
$$(\sigma_\ell,\pi) \in \mathcal{S}_H \wr \mathcal{C}_L, \qquad (\sigma_\ell,\pi) \cdot \mathbf{A}^{\ell,h}_{n_1,n_2} = \mathbf{A}^{\pi^{-1}(\ell),\; \sigma_{\pi^{-1}(\ell)}^{-1}(h)}_{n_1,n_2}.$$LEMON is designed to be invariant to the symmetries formalized above.
Our architecture, LEMON, is based on a Message Passing Neural Network (MPNN), modifying the update function \(f_{\mathrm{up}}:\mathbb{R}^{L \times H \times d}\to\mathbb{R}^{L \times H \times d}\) to be equivariant to the group \(\mathcal{W}\), where \(d\) is the hidden feature dimension.
Making \(f_{\mathrm{up}}\) equivariant to \(\mathcal{W}\). Building on the characterization of linear \(\mathcal{W}\)-equivariant maps by Wang, Albooyeh, and Ravanbakhsh (NeurIPS 2020), we extend their construction to nonlinear neural networks, yielding a more general class of \(\mathcal{W}\)-equivariant maps. We define \(f_{\mathcal{W}}:\mathbb{R}^{L \times H}\to\mathbb{R}^{L \times H}\) as follows, omitting feature channels for clarity:
$$f_{\mathcal{W}}(\mathbf{A}_{n_1,n_2}) = f_{\mathcal{C}_L}(\mathbf{A}_{n_1,n_2}\mathbf{1}_H)\mathbf{1}_H^{\top} + f_{\mathcal{S}_H}^{\mathrm{siamese}}(\mathbf{A}_{n_1,n_2}),$$ $$\big[f_{\mathcal{S}_H}^{\mathrm{siamese}}(\mathbf{A}_{n_1,n_2})\big]^{\ell} := f_{\mathcal{S}_H}(\mathbf{A}_{n_1,n_2}^{\ell}), \qquad \forall\,\ell \in [L].$$Here \(\mathbf{1}_H \in \mathbb{R}^{H}\) is the all-ones vector. The functions \(f_{\mathcal{C}_L}:\mathbb{R}^{L}\to\mathbb{R}^{L}\) and \(f_{\mathcal{S}_H}:\mathbb{R}^{H}\to\mathbb{R}^{H}\) can be any functions equivariant to \(\mathcal{C}_L\) and \(\mathcal{S}_H\), respectively, with the same \(f_{\mathcal{S}_H}\) shared across all layers. Adding the two paths gives a \(\mathcal{W}\)-equivariant map; see the illustration of \(f_{\mathcal{W}}\) below.
LEMON is online. Each generated token contributes a new attention row, which adds a node and incoming edges to the graph. Forward-only message passing, causal cross-token attention, and a prediction head that scores tokens independently ensure that \(\hat{y}_n\) depends only on tokens \(m \le n\). LEMON can therefore score tokens as they arrive, with the same predictions as within the completed response. Appending each node and its edges costs linear time in the prefix length.
Setup. We use a Leave-One-Out (LOO) evaluation protocol — we train on five LLMs and test zero-shot on the sixth. The held-out LLM contributes no labels to training or model selection. We repeat this for all six LLMs, training separate monitors for hallucination and jailbreak monitoring; see illustration below.
We consider two tasks: hallucination monitoring and jailbreak monitoring. For hallucination monitoring, we use the RAGTruth dataset and predict hallucinations at the token level as tokens are generated. For jailbreak monitoring, we predict attack success from the prompt alone on RedBench, using a universal GCG suffix across requests and LLMs.
| Unseen LLM | Baselines | LEMON (Ours) | |||||
|---|---|---|---|---|---|---|---|
| Prob | LB | HS | CHARM | LB+ Align |
\(\mathcal{W}\) | \(\mathcal{W}\)per-cell | |
| Llama- | 57.8 | 48.8 | 52.9 | 45.5 | 61.3 | 71.4 | 74.9 |
| Llama- | 52.3 | 53.9 | 52.5 | 57.3 | 54.2 | 73.8 | 75.5 |
| Mistral- | 67.6 | 49.5 | 51.0 | 42.2 | 57.5 | 68.2 | 68.5 |
| Mistral- | 58.3 | 52.4 | 50.3 | 44.2 | 60.6 | 63.9 | 64.8 |
| Qwen2.5- | 61.6 | 54.3 | 49.3 | 41.9 | 50.1 | 66.0 | 66.2 |
| Qwen2.5- | 61.1 | 50.0 | 52.2 | 57.8 | 58.7 | 63.6 | 66.3 |
| Mean | 59.8 | 51.5 | 51.4 | 48.1 | 57.1 | 67.8 | 69.4 |
Each row averages three RAGTruth tasks: summarization, question answering, and data-to-text. Mean covers all 18 LLM/task shards.
| Unseen LLM | Baselines | LEMON (Ours) | |||
|---|---|---|---|---|---|
| Attn→ Sys |
CHARM | HS | \(\mathcal{W}\) | \(\mathcal{W}\)per-cell | |
| Llama- | 59.1 | 30.4 | 73.1 | 75.1 | 62.6 |
| Llama- | 47.8 | 73.7 | 26.4 | 69.5 | 66.5 |
| Mistral- | 61.5 | 53.9 | 50.9 | 67.5 | 59.2 |
| Mistral- | 47.3 | 58.3 | 48.7 | 55.0 | 57.3 |
| Qwen2.5- | 67.6 | 38.5 | 45.7 | 63.9 | 64.8 |
| Qwen2.5- | 67.8 | 46.1 | 38.6 | 59.3 | 69.1 |
| Mean | 58.5 | 50.1 | 47.2 | 65.0 | 63.3 |
Predict attack success on each unseen LLM; mean covers all six LLMs.
LEMON achieves the highest mean ROC-AUC on both tasks, substantially outperforming baselines that do not explicitly account for layer–head symmetries. These results highlight the value of symmetry-aware architectures for transferring monitors to unseen LLMs.
@article{barshalom2026lemon,
title = {LEMON: Equivariant Learning over Attention Maps for Zero-Shot Misbehavior Monitoring on New LLMs},
author = {Bar-Shalom, Guy and Geva, Mor and Frasca, Fabrizio and Maron, Haggai},
journal = {arXiv preprint},
year = {2026}
}