Measuring Hallucinations: How Do You Test the Factuality of an LLM?

A guide for developers and data engineers on quantifying model reliability.

What is a hallucination in an LLM?

A hallucination occurs when a Large Language Model (LLM) generates text that sounds syntactically and semantically plausible, but is factually incorrect or does not logically follow from the provided context. In the context of enterprise applications, hallucinations represent the biggest obstacle to safe and reliable deployment.

Key Measurement Methods

Structurally measuring these errors requires automated evaluation pipelines. The most effective methods include:

Groundedness & Citations

When building Retrieval-Augmented Generation (RAG) systems, the focus shifts from general world knowledge to groundedness: the degree to which the answer is anchored in the documents you provide.

Best Practice: Force the model to use inline citations to specific paragraphs in the source. If a claim in the output cannot produce a corresponding citation, the likelihood of an 'unfaithful' hallucination is significantly higher.

Example Test Setup

A robust benchmark for factuality can be set up as follows:

  1. Dataset creation: Compile 100 factual questions linked to verified source texts.
  2. Inference: Have the LLMs under test generate answers purely based on the provided source text (temperature = 0).
  3. Claim extraction: Use a small model to break down the output into atomic claims (e.g., "The moon is gray", "The moon is made of cheese").
  4. Verification: Run an LLM-as-a-Judge pipeline via the API environment to validate for each claim whether it appears in the source text.

Do you have questions about setting up your own testing pipeline? Share your approach or ask for feedback in our developer community.

Evaluation Table: Benchmark Results

In the structure below, we periodically publish the scores of various open-source and commercial models based on our standardized RAG factuality benchmark. (Note: the table currently shows the structure with placeholders).

Model / Provider Parameters Groundedness (0-100) Factuality Index Hallucination Rate
[Model Name A] [X]B TBD TBD -%
[Model Name B] [X]B TBD TBD -%
[Model Name C] API TBD TBD -%