Shaking to Reveal: Perturbation-Based Detection of LLM Hallucinations

Jinyuan Luo, Zhen Fang, Yixuan Li, Seongheon Park, Ling ChenarXiv 2025 · OpenReview

Abstract

Hallucination remains a key obstacle to the reliable deployment of large language models (LLMs) in real-world question answering tasks. A widely adopted strategy to detect hallucination, known as self-assessment, relies on the model's own output confidence to estimate the factual accuracy of its answers. However, this strategy assumes that the model's output distribution closely reflects the true data distribution, which may not always hold in practice. As bias accumulates through the model's layers, the final output can diverge from the underlying reasoning process, making output-level confidence an unreliable signal for hallucination detection. In this work, we propose Sample-Specific Prompting (SSP), a new framework that improves self-assessment by analyzing perturbation sensitivity at intermediate representations. These representations, being less influenced by model bias, offer a more faithful view of the model's latent reasoning process. Specifically, SSP dynamically generates noise prompts for each input and employs a lightweight encoder to amplify the changes in representations caused by the perturbation. A contrastive distance metric is then used to quantify these differences and separate truthful from hallucinated responses. By leveraging the dynamic behavior of intermediate representations under perturbation, SSP enables more reliable self-assessment. Extensive experiments demonstrate that SSP significantly outperforms prior methods across a range of hallucination detection benchmarks.

Introduction

Large Language Models (LLMs) frequently generate plausible-sounding but factually incorrect information, a phenomenon known as hallucination. While "self-assessment"—using the model's own confidence scores—is a standard detection strategy, it is often undermined by output-layer biases. As information traverses dozens of transformer layers, errors accumulate, causing the final output probability to diverge from the model's internal reasoning.

Recent research has turned toward intermediate representations (hidden states) to find a more reliable truthfulness signal. However, these states are complex and difficult to interpret directly. This paper introduces Sample-Specific Prompting (SSP), a framework that detects hallucinations by measuring how internal representations shift when the model is "shaken" by tailored perturbations.

The SSP Framework

The core hypothesis of SSP is that factual knowledge is anchored in well-structured internal representations that are highly sensitive to input context. In contrast, hallucinations are less grounded and exhibit lower sensitivity to perturbations in intermediate layers.

The SSP framework architecture, illustrating the flow from input to truthfulness score via noise-perturbed intermediate representations.

As shown in Figure 1, the SSP workflow consists of three primary components:

  1. Dynamic Noise Generation: Using a "SeedPrompt," the system generates a stylistic perturbation tailored to the specific question-answer pair. This ensures the noise alters the "vibe" or style without changing the underlying meaning.
  2. Lightweight Learning: A small Multi-Layer Perceptron (MLP) acts as a prompt generator, learning to optimize these noise prompts to maximize the representational shift for truthful answers while minimizing it for hallucinations.
  3. Contrastive Training: The system is trained using a contrastive loss to map representations into a space where the cosine distance between an original and a perturbed state is large for truthful responses and small for hallucinations.

Experimental Results

The authors evaluated SSP using LLaMA-3-8B and Qwen-2.5-7B across four diverse benchmarks: TruthfulQA, TriviaQA, CoQA, and TydiQA-GP.

Performance comparison of SSP against various baselines and ablation variants across four QA benchmarks.

As detailed in Figure 6, SSP significantly outperformed baseline methods. On the TruthfulQA benchmark, it achieved a 4.78% improvement in AUROC over previous top-tier methods. Ablation studies (SSP w/o Encoder and SSP w/o SeedPrompt) confirm that both the dynamic noise generation and the lightweight encoder are critical to the framework's success.

Key findings include:

  • The Middle Layer Sweet Spot: Hallucination detection performance peaks in the middle layers, where the model has moved beyond raw text processing but has not yet been overwhelmed by output-layer bias.
  • Efficiency: Unlike sampling-based methods (e.g., Semantic Entropy) that require multiple generations, SSP only analyzes the representation shift of a single answer, making it significantly faster for deployment.
  • Generalization: Models trained on one dataset (e.g., TriviaQA) maintained high accuracy when tested on others (e.g., TydiQA-GP), suggesting that sensitivity to perturbation is a fundamental property of latent knowledge storage.

Conclusion

SSP provides a robust, perturbation-based approach to hallucination detection by leveraging the sensitivity of intermediate representations. While highly effective, the method currently requires access to internal model weights, limiting its use to open-source models. Future work may focus on localizing specific hallucinated tokens and developing more complex scoring mechanisms to further refine detection accuracy.

Summary updated

BibTeX
@misc{luo2025shaking,
  author = {Jinyuan Luo and Zhen Fang and Yixuan Li and Seongheon Park and Ling Chen},
  title = {{Shaking to Reveal: Perturbation-Based Detection of LLM Hallucinations}},
  year = {2025},
  eprint = {2506.02696},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.02696},
}
Figure