Skip to content

How to detect LLM hallucinations

You detect hallucinations by checking each output against a source you trust (reference-based), or against the model's own consistency or a judge model (reference-free). Then you run those checks on live traffic continuously, not only before launch.

By Arun Prasad · Published · Last updated

On this page

Why LLM hallucinations matter

Hallucinations matter because nothing about the text looks wrong, and in agents the problem is harder to see: a tool can return a 200, the task can still fail, and standard monitoring won't catch it.

A hallucination is fluent output that the source or the facts do not support. An agent can retrieve the right document, call the right tool, finish every step, and still tell the user something the document never said. Standard monitoring shows the request went through, not whether the answer was right.

Step 1: Decide what counts as a hallucination in your app

Write down what "unsupported" means for your agent and name the source of truth each answer must agree with. Without that, no detection method has anything to check against.

For most agents the source of truth is one of three things:

  • Documents or a knowledge base the agent retrieves from.
  • Tool results, such as an order status returned by an API.
  • The system prompt, which holds your rules and constraints.

Decide whether your app treats both kinds of unsupported output as failures: content the source can't confirm, and content that contradicts the source. A support agent quoting a refund window that isn't in the policy adds content. One that reverses the policy contradicts it.

Step 2: Pick a detection method

The best method depends on whether you have a source of truth to check against. If you do, use reference-based comparison; if not, pick a reference-free method like self-consistency or LLM-as-judge.

  • Reference-based comparison. Compare the answer to the source text or a known-good answer, for example with sentence similarity. It needs the reference.
  • Log probability. Look at how confident the model was in its own tokens.
  • Self-consistency sampling. Generate the same answer several times and check whether the model agrees with itself across runs. Because it uses only the model's own outputs, it needs no external knowledge base.
  • LLM-as-judge. A second model reads the exchange and scores it. A judge doesn't strictly need a reference answer, but giving it the source to check against is a sensible default.

If you have a source of truth, use it first. Use the reference-free methods where you don't, or as a second signal.

Step 3: Score every production trace and keep the evidence

Run your chosen check on live traffic continuously, and store the reason and evidence next to each verdict. Without evidence, scores can't be reviewed; without continuous scoring, you only cover questions you thought of in advance.

Three things make this work:

  • Coverage. Decide whether the check runs on every trace or a sample, and write the limit down. A sampled check can miss a rare failure.
  • Evidence. Each verdict should point to the step it judged, the source it was checked against and a short reason, so a person can agree or disagree in seconds.
  • Context. Agent steps such as tool calls and retries appear in your traces only if your integration sends them, so a check can only use what it receives.

The section "How this looks in production" shows how PRISM does this.

Step 4: Group repeated failures, fix them and check again

Group failures by cause, fix the largest group first, and measure whether the failure rate fell. One bad answer is an anecdote. 40 sessions with the same bad answer is a fix you can prioritize.

For each group, look for the likely cause: a prompt that allows guessing, a missing document, a retrieval step that returns the wrong passage, or a tool result the agent misreads. Then compare failure rates on comparable traffic before and after the change. Re-checking the same kinds of cases is what tells you the fix held, not just that it looked right on one example.

How this looks in production

PRISM by Block Convey runs evaluators on real runs. An evaluator is a reusable evaluation criterion, and there are two kinds of rules:

  • Deterministic rules give the same verdict for the same input, use no model and run on 100% of sessions.
  • LLM-as-judge rules have a model read the exchange. The judge scores every incoming trace until the plan's daily allowance is used up. After that, only the deterministic rules run. See PRISM pricing for plan allowances.

Each verdict links to the rule, the span, the source checked and the reason, so a reviewer can see why a trace was flagged. Scores are stored with the trace in agent observability, alongside its request, response, model, cost and timing. PRISM also groups repeated failures into patterns and shows how many sessions share each one, which is Step 4 above. After a fix is merged, it compares pass rates for the 7 days before and the 7 days after the merge.

Python SDK example:

Example · text
from prismtrace import PRISMtrace

client = PRISMtrace(api_key="pt-sk-...")

client.trace(
    project_id="my-project",
    model="gpt-4o",
    input_messages=[{"role": "user", "content": "What is the refund window?"}],
    output_message="You have 60 days to request a refund.",
    latency_ms=320
)

PRISM scores the trace automatically on arrival. For a hallucination evaluator you configure in the Evaluators Hub, the verdict includes the rule name, the span ID and a short reason, for example, that the output states 60 days when your Knowledge Base document says 30. A reviewer can open that trace, read the evidence and confirm or override the verdict in seconds.

You can send traces with the Python SDK, the HTTP API, OpenTelemetry or the zero-code proxy. See integrations for supported models and frameworks.

Limits to know about:

  • Core scores are on the Free plan. Custom evaluators and the Evaluators Hub need Builder or above.
  • If you use content-free ingest, which drops prompt and response text from storage, those traces get no LLM-judge scores.
  • Once the plan's daily judge allowance is used up, only deterministic rules continue.
  • A verdict is a signal for a person to review, not proof. Read examples before you trust any judge.

Common mistakes

Most of these mistakes come down to trusting a status or a score without checking it against a source.

  • Treating a successful tool call as a correct answer. A 200 means the request went through, not that the answer was right. Fix: score the answer against the source separately from the step status.
  • Checking only before launch. A test set covers the questions you expected. Fix: run the same checks on production traffic, where real users ask things you didn't plan for.
  • Relying on one method and one score with no source of truth. A single number hides what it measured. Fix: define the source of truth in Step 1, use a reference-based check where you can, and add a reference-free method as a second signal.
  • Trusting a judge without reading examples. A judge can be wrong in ways you only see by reading its verdicts. Fix: review a set of flagged and unflagged traces yourself, and have a person review disagreements. For ambiguous or high-stakes answers, automated checks work best when they filter traces down to the few a person needs to read. PRISM has a human review queue on Builder and above.

To see judge scores and evidence on your own agent, send traces to PRISM and view the verdicts with their evidence.

Can you detect hallucinations without a reference answer?

Yes, but with limits. A consistency check can confirm the model repeats itself, not that it is right, a model can be consistently wrong. For hallucination detection, pair reference-free methods with a source-based check when you have one.

Can a fine-tuned model catch hallucinations?

Yes, but test it on your own traffic first. This is an active research area, and published models vary widely. Before relying on a fine-tuned evaluator, run it on real examples from your agent to confirm it catches your app's hallucinations.

Do you need a human in the loop to catch hallucinations?

For ambiguous or high-risk answers, yes. No automated metric is perfect, and critical applications benefit from human review, with automated checks used to reduce the volume a person has to read. In PRISM, the human review queue is available on Builder and above.

Catch hallucinations in real traffic, with the proof

See PRISM's scores and evidence on your agent's live traces.

Paid plans from $20/month.