Skip to main content
Build a hallucination detection pipeline that combines pre-deployment evaluation with the Evals SDK and continuous production monitoring through LLM Observability enrichments and Evaluator Rules. Use this cookbook when: You want to monitor your RAG application for hallucinations across both testing and production environments. Time to complete: ~25 minutes
Prerequisites
  • Fiddler account with API access
  • LLM credential configured in Settings > LLM Gateway
  • pip install fiddler-evals fiddler-client pandas

The Two-Layer Approach

Hallucination detection works best as a two-layer pipeline:

Layer 1: Pre-Deployment Evaluation

1

Set Up and Connect

Use the RAG Health Metrics triad to distinguish hallucinations from other failure modes:
Replace URL, TOKEN, and credential names with your Fiddler account details. Find your credentials in Settings > Access Tokens and Settings > LLM Gateway.
2

Create Hallucination-Focused Test Cases

Design test cases that specifically probe for hallucination patterns:
3

Run the Diagnostic Evaluation

4

Interpret Results

Use the diagnostic workflow to classify failures:
Expected output:
Reading the diagnosis: The triad distinguishes why a response failed:
  • HALLUCINATION = Faithfulness fails (response fabricates information)
  • BAD RETRIEVAL = Context Relevance fails (wrong documents retrieved)
  • OFF-TOPIC = Answer Relevance fails (response doesn’t address the question)

Layer 2: Production Monitoring

For applications using Agentic Monitoring, configure Evaluator Rules to continuously evaluate production spans:
  1. Navigate to your application’s Evaluator Rules tab
  2. Add a rule for RAG Faithfulness
  3. Map evaluator inputs to your span attributes:
    • user_query → your query span attribute
    • rag_response → your response span attribute
    • retrieved_documents → your context span attribute
  4. Set alert thresholds (e.g., alert when faithfulness drops below 80%)
See Evaluator Rules for step-by-step instructions.

Combining Both Layers

The most effective hallucination detection pipeline uses both layers:

Next Steps


Source notebooks: