Detectors that read a language model's internal activations are among the cheapest ways to flag a hallucination, meaning a fluent statement that the source document or the world does not support. They have a known failure, though. A detector trained on web question answering sits near chance when it is moved to a new domain, because the directions it learned to read encode topic and writing style as much as truth. The shift from web prose to commercial contracts, privacy policies, or clinical evidence summaries is exactly this kind of style shift. These are also the settings where hallucinations matter most and where their form changes: legal and medical systems rarely invent entities. They cite the real case or the real drug and then get the relation wrong, for example by swapping plaintiff and defendant, turning "may" into "shall", or reporting a tentative finding as a definite one.
We propose to score each claim by the difference between the model's internal representation of that claim and its representations of a few minimally edited versions of it. The edits are role swaps, flipped modality or negation, and altered numbers or dates, all built from entities that already appear in the same document. The original claim and its edited versions share vocabulary, register, length, and domain, so the domain-specific part of the representation largely cancels in the difference. What remains is how the model internally weighs this relation against close alternatives, and that is exactly the quantity that separates insidious hallucinations from faithful statements. In short: train a small linear detector on these contrast vectors using cheap web-domain labels, then show that it transfers without retraining to contracts, privacy policies, case law, and medical evidence, where raw-activation detectors collapse.
Core Claim
A linear detector applied to claim-minus-counterfactual activation differences will keep most of its in-domain accuracy under domain-specific linguistic shift. The same detector applied to raw activations, or to activations that are only normalized per domain, will not. The gain should be largest on relational errors among genuine domain entities. The claim is falsifiable in two ways. If a simple per-domain mean-centering of raw activations recovers the same transfer, the contrast construction is unnecessary. If the model's own log-probability margin between the claim and its counterfactuals does as well as the learned detector on contrast vectors, the internal-state reading is unnecessary. Both checks are built into the experiments below.
Where This Sits
Two papers motivate the problem. What do Geometric Hallucination Detection Metrics Actually Measure? shows that activation-geometry statistics which detect errors almost perfectly within a single synthetic domain drop to AUROC 0.57–0.60 for factual incorrectness once domains are mixed. Beyond In-Domain Detection: SpikeScore for Cross-Domain Hallucination Detection shows that supervised activation probes fall to 0.5–0.6 AUROC out of domain because they latch onto domain-specific features.
Three papers supply partial remedies, and we differ from each. The geometric-metrics paper normalizes each statistic against lightly perturbed inputs and gains 34 AUROC points. Its perturbations are generic and its domains are elementary: multiplication, dates, counting. Our edits are structured, built from the document's own entities, and designed to isolate relational content in dense professional text. SpikeScore pressure-tests an answer with 20 generated follow-up turns and reads the sharpest jump in uncertainty. We need no generation at all, only a handful of forward passes over short edited claims that reuse the cached context. CED: Comparing Embedding Differences for Detecting Out-of-Distribution and Hallucinated Text also contrasts embeddings, but it pairs inputs with retrieved training samples. It notes that same-domain embeddings overlap heavily, which is the very regime of insidious hallucinations. Our contrasts come from the claim itself, not from a cached training set.
HARP: Hallucination Detection via Reasoning Subspace Projection attacks the same confound differently. It projects activations onto a subspace orthogonal to the dominant directions of the vocabulary-projection matrix, which removes "semantic" variance, and it transfers from TriviaQA to NQ Open. Web-to-web transfer is a weak test of linguistic shift, so we treat HARP both as a baseline and as a compatible component: contrast vectors can be projected into its subspace as well.
HalluGraph: Auditable Hallucination Detection for Legal RAG Systems via Knowledge Graph Alignment targets the same entity and role substitutions through knowledge-graph alignment. It needs long contexts and an extra extraction model, and it falls to chance on short-context TruthfulQA. Our edits reuse its insight about which errors matter but read them from the generator's own states. The error taxonomy comes from Hallucination-Free? Assessing the Reliability of Leading AI Legal Research Tools, which reports that real legal RAG tools cite real authorities with false holdings at hallucination rates of 17–33%. A second source is Evaluating large language models on medical evidence summarization, which documents models turning tentative clinical findings into definite ones.
Research Program
The first component is a counterfactual editor. We break each generated answer into atomic claims. For each claim, the editor produces $K$ (around four to eight) minimal edits from four families, each targeting a documented failure mode. The first family swaps the roles of two entities of the same type found in the context, using legal and medical entity recognizers; the LegalEval entity categories in SemEval-2023 Task 6: LegalEval - Understanding Legal Texts cover parties, courts, statutes, and dates. The second flips negation or modality (may/shall/must, associated-with/causes). The third substitutes a different number or date from the same document. The fourth replaces a cited provision or precedent with another one cited elsewhere in the context. Edits are rule-based by default. A small model is used only as a fallback for rewording, and we will report results with the rule-only editor so that no extraction model's errors leak in.
The second component is the score. Let $h(c)$ be the mean hidden state at a chosen layer over the tokens of claim $c$, read with the source document in context, and let $\tilde c_1,\dots,\tilde c_K$ be its edits. The detector is
$$s(c) = w^\top\Big(h(c) - \tfrac{1}{K}\textstyle\sum_{k=1}^{K} h(\tilde c_k)\Big),$$
where $w$ is a linear direction fit by logistic regression on labeled source-domain claims. Anything shared by the claim and its edits, including domain register, syntax, length, and entity vocabulary, contributes nothing to the difference to first order. This is why we expect transfer. Because the context's cached keys and values are reused, the cost is $K+1$ short prefill passes rather than $K+1$ generations.
The third component is the evaluation data, which is the part that does not yet exist. We train only on web-domain labels: RAGTruth's span-annotated responses from RAGTruth: A Hallucination Corpus for Developing Trustworthy Retrieval-Augmented Language Models, plus TriviaQA for the closed-book variant. For targets, we have Llama-3.1-8B and Qwen3-8B (models used in the SpikeScore evaluation) answer document-grounded questions in four domains. The first is contracts, built from clause-category questions over CUAD: An Expert-Annotated NLP Dataset for Legal Contract Review. The second is privacy policies, from PolicyQA: A Reading Comprehension Dataset for Privacy Policies. The third is Indian case law, drawn from LegalEval judgments and restricted to sentences labeled with their rhetorical roles, so that claims about holdings can be checked against Ratio and Ruling sentences. The fourth is Cochrane evidence summaries, following the medical summarization study. Expert span annotations in CUAD and PolicyQA allow most claims to be labeled semi-automatically against gold spans. A stratified sample of roughly 1,500 claims across domains will be labeled by trained annotators (law and medical students) to measure label noise. We also evaluate on the HalluGraph synthetic contract and case-law sets, because they isolate role substitution.
Baselines
The naive reference point is a raw-activation probe of the SAPLMA type trained on RAGTruth and applied unchanged to the target domains. SpikeScore and the geometric-metrics paper report that such probes reach only 0.5–0.6 AUROC out of domain, and we expect to reproduce that range. Every method below uses the same generator, the same layer search done on source-domain validation data only, and the same labeled source data.
The strongest training-free competitor for cross-domain activation detection is SpikeScore, run with its published 20-turn protocol on top of the same base probe. Its reported average cross-domain AUROC is about 0.78–0.79 when trained on Math and evaluated on the other domains (Beyond In-Domain Detection: SpikeScore for Cross-Domain Hallucination Detection). We will report its cost in generated tokens alongside ours. Beating it means higher target-domain AUROC at a lower inference cost, or equal AUROC at a fraction of the cost.
The strongest competitor for context-grounded verification is an Auto-GDA verifier, Auto-GDA: Automatic Domain Adaptation for Efficient Grounding Verification in Retrieval-Augmented Generation. It is a DeBERTa model adapted per domain with synthetic claims generated over unlabeled target documents, and it reports an average ROC-AUC of 0.878 on RAGTruth, SummEdits, and LFQA-Verification, close to GPT-4o's 0.883. It gets something we deliberately withhold from our method: a separate adaptation run on unlabeled documents from each target domain. We will give it the same CUAD, PolicyQA, LegalEval, and Cochrane documents. If our single source-trained detector matches it without any per-domain adaptation, that is a win. If it clearly loses, we will report the gap as the price of zero adaptation.
We also run HARP's reasoning-subspace detector, trained on the same source data. Its reported TriviaQA AUROC is 92.8 on Qwen-2.5-7B, but no reported result was found on Lacuna for HARP under legal or clinical domain shift. We run the perturbation-normalized geometric statistics, whose reported multi-domain AUROC on synthetic domains is 0.96 for HS-Norm and 0.89 for AS-Norm. We run HalluGraph only on its own synthetic legal sets, where it reports AUC 0.94 on contracts and 0.84 on case law, and BERTScore, which reports 0.60 on contracts.
Two ablations isolate the key ingredient. In the first, per-domain mean-centering subtracts the target domain's average activation, estimated from unlabeled target claims, before applying the raw probe. In the second, random-perturbation contrast replaces our structured edits with generic paraphrase and noise perturbations of the same count.
Why not just…?
Why not just mean-center activations per domain? If domain shift is mostly a constant offset in activation space, centering on unlabeled target data removes it at almost no cost. This is the most serious threat to the proposal. Our argument that it falls short is that domain shift in contracts is not a single offset: syntax and register vary within a document, across clause types, and across rhetorical roles. Per-claim contrast cancels the shift locally, while centering cancels it only on average. The mean-centering ablation settles this directly. If it comes within two AUROC points of contrast probing on all four target domains, we will conclude that the contrast construction is unnecessary and report that.
Why not just compare the model's log-probabilities of the claim and its counterfactuals? This is our own idea without the learned detector, and it may be enough. It fails if the model's surface preference for fluent or familiar phrasing dominates its likelihood. That is plausible for certainty illusions, where "shall" may simply be the more common legal word. We report the likelihood margin as a baseline with no training at all. The learned detector must beat it, especially on the modality family, to justify itself.
Why not just adapt a verifier per domain with Auto-GDA? For a single high-value domain with a static corpus, that may be the right engineering choice, and Auto-GDA reports near-GPT-4o accuracy. The case for our method is a single detector that needs no corpus, no synthetic-data pipeline, and no retraining for each new domain, and that also reads the generator's own states rather than only checking entailment. The head-to-head above shows how much accuracy that convenience costs.
Why not just continually pre-train on domain text? CUAD reports that 8GB of extra legal pre-training improved extraction by only about 3%. The guideline-consistency study Prompt engineering in consistency and reliability with the evidence-based guideline for LLMs found that fine-tuning GPT-3.5 on guidelines did not reliably improve consistency. Domain exposure also does nothing to make an existing detector stop reading style. We will not run this as a full baseline, and we flag that as a limitation.
Decisive Checks
The primary result is AUROC of a single RAGTruth-trained detector on each of the four target domains, compared against the in-domain AUROC of a detector trained on a held-out half of the target labels. The quantity of interest is the fraction of that in-domain ceiling each method retains. We break results down by edit family and by the four RAGTruth-style error types, and we expect the largest gains on subtle conflicts and role swaps.
A mechanistic check tests the stated reason the method should work. We fit a linear classifier to predict domain from raw activations, from mean-centered activations, and from contrast vectors. The idea predicts that domain is nearly unpredictable from contrast vectors while hallucination stays predictable. If domain remains easily decodable and transfer still improves, our explanation is wrong even if the method works.
We also report cost per claim in forward-pass tokens against SpikeScore. We test the closed-book variant on TriviaQA-to-medical transfer, where the edits come from the claim alone. Finally, we run a negative control in which the edits are swapped across unrelated claims. Because those edits no longer form minimal pairs with the claim, the contrast should stop cancelling domain style, and any transfer advantage should disappear.
References
- What do Geometric Hallucination Detection Metrics Actually Measure?
- Beyond In-Domain Detection: SpikeScore for Cross-Domain Hallucination Detection
- CED: Comparing Embedding Differences for Detecting Out-of-Distribution and Hallucinated Text
- HARP: Hallucination Detection via Reasoning Subspace Projection
- HalluGraph: Auditable Hallucination Detection for Legal RAG Systems via Knowledge Graph Alignment
- Hallucination-Free? Assessing the Reliability of Leading AI Legal Research Tools
- Evaluating large language models on medical evidence summarization
- SemEval-2023 Task 6: LegalEval - Understanding Legal Texts
- RAGTruth: A Hallucination Corpus for Developing Trustworthy Retrieval-Augmented Language Models
- CUAD: An Expert-Annotated NLP Dataset for Legal Contract Review
- PolicyQA: A Reading Comprehension Dataset for Privacy Policies
- Auto-GDA: Automatic Domain Adaptation for Efficient Grounding Verification in Retrieval-Augmented Generation
- Prompt engineering in consistency and reliability with the evidence-based guideline for LLMs