LettuceDetect: A Hallucination Detection Framework for RAG Applications
Ádám Kovács, Gábor Recski · 2025
Read LettuceDetect: A Hallucination Detection Framework for RAG Applications by Ádám Kovács, Gábor Recski (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2502-17125.txt.
Introduction
Ádám Kovács and Gábor Recski present LettuceDetect, a framework for catching made-up claims in retrieval-augmented generation, in a 2025 paper. Such systems fetch outside knowledge before answering, yet they still hallucinate. Older detectors either choke on long context or lean on huge language models that cost too much to run on every answer.
LettuceDetect builds on ModernBERT, which reads up to eight thousand tokens at once, and trains on the RAGTruth benchmark. It labels tokens in each context, question, and answer triple, flagging exactly which claims lack support. It beats all earlier encoder models and most prompt-based ones, while staying roughly thirty times smaller and fast enough for real use.
Catalog record
| CREATOR | Ádám Kovács, Gábor Recski |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 21 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2502-17125
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
LettuceDetect: A Hallucination Detection Framework for RAG Applications Ádám Kovács, Gábor Recski Abstract Retrieval-Augmented Generation (RAG) systems remain vulnerable to hallucinated answers despite incorporating external knowledge sources. We present LettuceDetect , a framework that addresses two critical limitations in existing hallucination detection methods: (1) the context window constraints of traditional encoder-based methods, and (2) the computational inefficiency of LLM-based approaches. Building on ModernBERT’s extended context capabilities (up to 8k tokens) and trained on the RAGTruth benchmark dataset, our approach outperforms all previous encoder-based models and most prompt-based models, while being approximately 30 times smaller than the best models. LettuceDetect is a token-classification model that processes context-question-answer triples, allowing for the identification of unsupported claims at the token level. Evaluations on the RAGTruth corpus demonstrate an F1 score of 79.22% for example-level detection, which is a 14.8% improvement over Luna, the previous state-of-the-art encoder-based architecture. Additionally, the system can process 30 to 60 examples per second on a single GPU, making it more practical for real-world RAG applications. 1 Introduction Large Language Models (LLMs) have made significant progress in recent years in terms of their performance OpenAI et al. 2024 ; Grattafiori et al. 2024 ; Team et al. 2024 . However, the biggest obstacle to their usage in real-world applications is their tendency to hallucinate Kaddour et al. 2023 ; Huang et al. 2025 . Retrieval-Augmented Generation (RAG) is a method that enhances LLMs by supporting answers with context documents and retrieving knowledge from external sources, prompting the LLMs to ground their responses based on this information Gao et al. 2024 . This technique is widely used to minimize hallucinations of LLMs. Despite the incorporation of context documents in RAG, LLMs continue to experience hallucinations Niu et al. 2024 . Hallucinations are defined as outputs that are nonsensical, factually incorrect, or inconsistent with the provided evidence Ji et al. 2023 . Ji et al. 2023 categorizes these errors into two types: Intrinsic hallucinations , which arise from the model’s inherent knowledge, and Extrinsic hallucinations , which occur when responses fail to be grounded in the provided context, such as in the case of RAG hallucinations Niu et al. 2024 . While RAG can mitigate intrinsic hallucinations by grounding LLMs in external knowledge, extrinsic hallucinations persist due to imperfect retrieval processes or the model’s tendency to prioritize its intrinsic knowledge over external context Sun et al. 2025 , leading to factual contradictions. As LLMs remain prone to hallucinations, their utilization in high-risk settings, such as medical or legal fields, may be jeopardized Lozano et al. 2023 ; Magesh et al. 2024 . We present LettuceDetect , a hallucination detection framework that utilizes ModernBERT Warner et al. 2024 . Our approach trains a token-classification model to predict whether a token is supported by context documents and a question, determining if it is hallucinated. We frame this task as predicting tokens in the answers generated by large language models (LLMs), based on the provided context documents and the posed question. Our models are trained using the RAGTruth dataset Niu et al. 2024 . The architecture we employ is similar to Luna Belyi et al. 2025 , as we train an encoder-based model for this task. A demonstration of our web application is displayed in Figure 6 . All components of our system are released under an MIT license and can be accessed on GitHub 1 1 1 https://github.com/KRLabsOrg/LettuceDetect and via pip by installing the lettucedetect 2 2 2 https://pypi.org/project/lettucedetect/ package. The trained models are published on Hugging Face also under MIT licenses. We have made available both a large model 3 3 3 https://huggingface.co/KRLabsOrg/lettucedect-large-modernbert-en-v1 and a base model 4 4 4 https://huggingface.co/KRLabsOrg/lettucedect-base-modernbert-en-v1 . We believe our contribution will be valuable to the community, particularly since many effective hallucination detection methods are either under non-permissive licenses or depend on larger LLM-based models. The remainder of this paper is structured as follows: Section 2 reviews recent methods for hallucination detection. Section 4 details our method for training an encoder-based hallucination detection model built on ModernBERT. Section 5 presents our findings on the example and span-level tasks using the RAGTruth dataset. 2 Related work ModernBERT BERT Devlin et al. 2019 was one of the first major successes of applying the Transformer architecture Vaswani et al. 2017 to natural language understanding. BERT uses only the Transformer’s encoder blocks in a bidirectional fashion, allowing it to learn context from both directions. As a result, BERT quickly became the backbone of many NLP pipelines for tasks like classification, question answering, named entity recognition, etc. BERT’s initial design included certain limitations, such as a maximum sequence length of 512 tokens and less efficient attention mechanisms, leaving room for architectural upgrades and larger-scale training. Despite the current rise of popularity of LLM-based architectures in NLP, such as GPT-4 OpenAI et al. 2024 , Mistral Jiang et al. 2023 or Llama-3 Grattafiori et al. 2024 , encoder-based models are still widely used in many applications, because of their much smaller size and better-suited inference requirements that make them suitable for real-world applications. Figure 1: A web demo of our application built in Streamlit 6 6 6 streamlit.io . It features three input fields: question, context, and answer. The output shows the highlighted hallucinated spans. ModernBERT Warner et al. 2024 is a state-of-the-art encoder-only transformer architecture that incorporates several modern design improvements over the original BERT model. It utilizes several enhancements, including rotary positional embeddings (RoPE) Su et al. 2024 instead of traditional absolute positional embeddings. Additionally, it features an alternating local-global attention mechanism as described in Team et al. 2024 , allowing it to efficiently manage sequences of up to 8,192 tokens. This makes it significantly more effective for long-context tasks, such as modern information retrieval Nussbaum et al. 2025 ; Zhang et al. 2024 . ModernBERT features a hardware-aware design and an expanded training corpus of 2 trillion tokens, including textual and code data. As a result, it achieves superior performance on various downstream benchmarks, such as GLUE for classification and BEIR for retrieval (while also maintaining faster inference speed) Nussbaum et al. 2025 ; Zhang et al. 2024 . Based on these findings, the main part of our paper is to use the advancements of ModernBERT in the hallucination detection of LLMs in an RAG setting. In this domain, long-context awareness is an inevitable feature. Hallucination Detection can vary in granularity, ranging from example-based detection (which assesses if an answer contains hallucinations) to token, span, or sentence-level detection Niu et al. 2024 . The methods for detecting hallucinations also differ based on the techniques employed. Prompt-based Techniques typically utilize zero or few-shot large language models (LLMs) to identify hallucinations in LLM-generated responses. Few-shot or fine-tuned evaluation frameworks, such as RAGAS Es et al. 2024 , Trulens 7 7 7 https://www.trulens.org/ , and ARES Saad-Falcon et al. 2024 , have emerged to provide hallucination detection at scale using LLM judges. However, real-time prediction remains a challenge for these methods. Other prompt-based approaches, like the zero-shot method SelfCheckGPT Manakul et al. 2023 , employ stochastic sampling to identify inconsistencies across multiple response variants. Rather than relying on a single prompt, Chainpoll Friel and Sanyal 2023 implements a series of verification steps to