What You'll Build
By the end of this project you'll have a complete Live RAG Hallucination Auditor — a tool that fetches real data through MCP, runs queries against it, and systematically scores both retrieval quality and generation faithfulness to catch AI mistakes before they reach anyone who matters.
- ✓An MCP-powered data fetcher that pulls live content into Claude's context window
- ✓A retrieval scorer that checks whether the right chunks were surfaced for each query
- ✓A generation faithfulness checker that flags any claim not supported by retrieved context
- ✓A hallucination log that records suspicious outputs with evidence trails
- ✓A printable audit report summarizing retrieval and generation scores side by side
What You'll Need
AI Tool
Claude (claude.ai or Claude Code) — you'll lean on its MCP tool support and its ability to reason about sources and faithfulness. ChatGPT works for the prompting steps but won't have native MCP access.
Text Editor
Any plain text editor — VS Code, Notepad++, or even a notes app. You'll paste prompts, collect Claude's outputs, and build your audit log in a simple file you can reference later.
Step-by-Step Instructions
Set Up Your MCP Data Source
Before you can audit anything, you need live data flowing into Claude. MCP tools let Claude reach outside its training data and pull real content — a webpage, a local file, or an API — directly into the conversation. This is the foundation everything else sits on. For this project, you'll configure Claude to fetch a real-world document or article and treat it as your retrieval corpus.
Use the prompt below to have Claude simulate the MCP setup and define what your data source will be. If you're running Claude Code with MCP enabled, you can wire up a real file system or web fetch tool. If you're using claude.ai in the browser, Claude will walk you through the configuration steps and produce a mock data payload you can work with throughout the rest of the project.
I want to build a RAG hallucination auditor and I need you to help me set up the data layer first. Act as my MCP configuration assistant. Here's what I need: (1) Describe which MCP tool I should use to fetch a live webpage or local text file into your context — give me the exact tool name and what it does. (2) Fetch (or simulate fetching) the following URL as my test corpus: https://en.wikipedia.org/wiki/Retrieval-augmented_generation — extract the main article text, ignore navigation and footers. (3) Return the fetched content chunked into 5 labeled sections with a one-sentence summary for each chunk. Format your output as a numbered list of chunks, each with: Chunk ID, Summary, and Full Text. This will be my retrieval corpus for the rest of the project.
What to look for: Claude should name a specific MCP tool (like mcp__fetch__fetch or the file system read tool), then return 5 clearly labeled chunks with summaries. If you're in a live MCP environment, you'll see it actually call the tool. In a standard chat session, it will simulate the fetch and produce representative chunks — both are fine for this project. Save all 5 chunks in your text editor; you'll use them in every step that follows.
Build the Retrieval Scorer
The first thing most people get wrong with RAG evaluation is treating retrieval and generation as one big black box. They see a bad answer and don't know if the wrong chunks were pulled, or if the right chunks were there but the model still made something up. This step fixes that — you'll create a retrieval scorer that grades chunk selection quality independently, before any generation happens.
You're going to give Claude a set of test questions, then ask it to identify which chunks from your corpus should have been retrieved for each question, and which chunks were retrieved (using a simulated retrieval step). The gap between those two things is your retrieval quality score. This mirrors exactly what production RAG evaluation frameworks measure.
Using the 5 corpus chunks from Step 1, I want you to build a retrieval scorer. Here's how it works: I'll give you 4 test questions. For each question, you must: (A) Identify the IDEAL chunks — the chunk IDs that genuinely contain the answer (use your knowledge of the chunks). (B) Simulate a basic keyword retrieval — pick the top 2 chunks a simple keyword search would return for that question. (C) Calculate a Retrieval Precision score: what fraction of the simulated-retrieved chunks are actually ideal? (D) Calculate a Retrieval Recall score: what fraction of ideal chunks were actually retrieved? Here are the 4 test questions: 1. What is the basic definition of RAG? 2. How does RAG reduce hallucinations? 3. What are the main limitations of RAG systems? 4. How does RAG differ from fine-tuning? Present your results as a table with columns: Question | Ideal Chunks | Retrieved Chunks | Precision | Recall | Retrieval Quality (Good / Partial / Poor).
What to look for: Claude should produce a clean table with Precision and Recall scores between 0 and 1 for each question. Look for cases where Recall is low — that means important chunks weren't retrieved, which will cause generation errors downstream. Copy this table into your audit file. Any row marked "Poor" or with Recall below 0.5 should be flagged — those questions are hallucination risks before the model even starts writing.
Generate Answers and Flag Hallucinations
Now you get to the generation layer. This is where hallucinations are born — the model receives its retrieved chunks (or in a poor retrieval case, the wrong ones) and writes an answer. Sometimes it sticks faithfully to the source. Sometimes it fills gaps with plausible-sounding fabrications. Your auditor needs to catch both patterns.
In this step you'll ask Claude to generate answers for your 4 test questions using only the simulated retrieved chunks from Step 2 — not its training knowledge. Then you'll immediately audit each answer for faithfulness. This is the core hallucination detection loop, and it mirrors exactly what production eval systems do after generation.
Now I want you to generate answers for each of the 4 questions from Step 2, but with a strict constraint: you may ONLY use information from the Retrieved Chunks column in your Step 2 table — not your training knowledge. After generating each answer, immediately audit it for hallucinations by doing the following: (1) Highlight every claim in the answer. (2) For each claim, label it as: GROUNDED (directly supported by the retrieved chunks), INFERRED (a reasonable logical inference from the chunks — flag but don't penalize), or HALLUCINATED (a claim with no support in the retrieved chunks). (3) Give each answer a Faithfulness Score from 0 to 1, where 1 means every claim is grounded. Format your output as: Question → Answer → Claim Audit Table → Faithfulness Score. At the end, show me a summary row with the average Faithfulness Score across all 4 questions.
What to look for: Pay attention to questions where retrieval quality was poor (from Step 2) — those answers should have lower Faithfulness Scores, which proves the retrieval-generation link. If you see a HALLUCINATED claim, check whether it was caused by a retrieval gap (the right chunk wasn't pulled) or a generation error (the right chunk was there but the model ignored it). That distinction matters enormously for fixing real RAG systems. Save the full output to your audit file.
Build the Hallucination Evidence Log
A hallucination you can't trace is a hallucination you can't fix. The difference between a toy eval and a real one is evidence — every flagged claim needs to be paired with the exact source text that proves (or disproves) it. This step turns your scattered audit notes into a structured log that someone could actually act on.
You'll ask Claude to compile every HALLUCINATED and INFERRED claim from Step 3 into a single evidence log, with a root cause diagnosis for each one. This is the kind of artifact a real AI team would take into a sprint to fix their pipeline — and now you'll have one too.
Using all the audit data from Steps 2 and 3, compile a Hallucination Evidence Log. For every claim labeled HALLUCINATED or INFERRED across all 4 questions, create one log entry with these fields: Claim ID (e.g. H-01, I-01), Question Number, The Exact Claim (copy it verbatim from the answer), Label (HALLUCINATED or INFERRED), Closest Source Text (the nearest thing in the retrieved chunks — or write 'No supporting text found'), Root Cause (choose one: Retrieval Gap — the right chunk wasn't retrieved; Generation Error — the right chunk was present but the model ignored it; Knowledge Bleed — the model used training data instead of context), Severity (High / Medium / Low), and Recommended Fix (one sentence). Present this as a formatted table, then write a 3-sentence Diagnosis Summary explaining the biggest pattern you see in the hallucination causes.
What to look for: The Root Cause column is the most important part. If most issues are "Retrieval Gap," your chunking or search strategy needs work. If most are "Generation Error," your system prompt needs stronger grounding instructions. If you see "Knowledge Bleed," Claude is ignoring the context window and using its training data instead — a serious issue in production. The Diagnosis Summary should give you a clear sentence you could actually put in a bug ticket.
Generate the Full Audit Report
Everything you've built across the last four steps — the MCP data fetch, the retrieval scores, the faithfulness scores, and the hallucination log — now gets rolled up into a single, shareable audit report. This is the deliverable. It's what you'd hand to a teammate, attach to a PR, or use to justify a change to your RAG pipeline.
The final prompt asks Claude to synthesize everything into a professional report with an executive summary, a scoring dashboard, and prioritized recommendations. After this step, you'll have a complete artifact that demonstrates the full audit cycle — from live data ingestion to final verdict.
Using all results from Steps 1 through 4, generate a complete RAG Hallucination Audit Report. Structure it exactly as follows — Section 1: Executive Summary (3 sentences covering what was audited, the overall system health, and the single most urgent fix). Section 2: Data Source (MCP tool used, corpus description, number of chunks). Section 3: Retrieval Scorecard — a table showing average Precision, average Recall, and a Retrieval Health rating of Green / Amber / Red. Section 4: Generation Scorecard — average Faithfulness Score across all questions, and a Generation Health rating of Green / Amber / Red. Section 5: Hallucination Summary — total HALLUCINATED claims, total INFERRED claims, root cause breakdown as percentages. Section 6: Top 3 Prioritized Recommendations, each with: Priority (P1/P2/P3), Problem, Evidence (cite a specific claim ID from Step 4), and Fix. Section 7: Verdict — a single sentence that starts with either 'This RAG system is PRODUCTION READY,' 'This RAG system NEEDS WORK before shipping,' or 'This RAG system IS NOT SAFE to ship,' followed by one sentence of justification. Format the whole report cleanly with headers.
What to look for: The report should feel like something a real AI engineering team would produce. The Verdict in Section 7 is the payoff — it should directly reflect the scores from Sections 3 and 4. If retrieval Recall was consistently low and Faithfulness averaged below 0.7, you should see a "NEEDS WORK" or "NOT SAFE" verdict. Copy the full report into your text editor and save it — this is your finished artifact.
Common Issues
Claude uses training knowledge instead of my chunks
This is "knowledge bleed" and it's very common. Add the phrase "You must treat your training data as inaccessible. If the retrieved chunks do not contain the answer, say 'Not enough information in the retrieved context' rather than inferring from prior knowledge" to your prompt. That constraint forces Claude to stay inside the retrieval boundary.
The retrieval simulation feels too generous
If Claude always retrieves the perfect chunks, it's optimizing rather than simulating. Add "Simulate a naive keyword retrieval that only matches on exact words, not meaning — it should miss semantically related chunks that don't share keywords with the query." This will surface realistic retrieval gaps.
MCP tool isn't connecting in my environment
If you're on claude.ai without a configured MCP server, that's fine — tell Claude "Simulate the MCP fetch by using your knowledge of the Wikipedia page on RAG to generate realistic chunks." The evaluation logic works identically whether the data was live-fetched or simulated. The MCP layer is about real production use — the audit methodology is what you're really learning.
Faithfulness scores are all 1.0 — no hallucinations found
Claude will sometimes grade itself too generously. Add: "Be a strict auditor. If a claim goes one word beyond what the retrieved text says, label it INFERRED. If it references something not in the retrieved chunks at all, label it HALLUCINATED. Err on the side of flagging." Push it to be a tough grader, not a lenient one.
What You Learned
MCP as a Live Data Layer
You saw how MCP tools extend Claude beyond its training data, giving it access to real documents at query time — the same pattern that powers real RAG systems in production.
Separate Retrieval and Generation Evals
You scored Precision, Recall, and Faithfulness as independent metrics rather than one blended quality score — the right way to diagnose where a RAG pipeline actually breaks down.
Hallucination Root Cause Analysis
You learned to distinguish Retrieval Gaps from Generation Errors from Knowledge Bleed — three different failure modes that each require a different fix.
Building a Shareable Eval Artifact
You turned raw AI outputs into a structured audit report with a scored dashboard and prioritized recommendations — the kind of deliverable that justifies engineering decisions with evidence.
Tips for Going Further
- →Connect a real MCP file system server and point it at a local folder of documents — your own notes, company docs, or a research paper — to run the full audit against content that actually matters to you.
- →Add a semantic retrieval simulation in Step 2 and compare its Precision/Recall against the keyword baseline — you'll see firsthand why embedding-based search outperforms keyword matching for most queries.
- →Turn the audit into a repeatable loop by writing a system prompt that runs all five steps automatically against any URL you drop in — an MCP-powered eval harness you can use on any new data source in seconds.
- →Stress-test the system with adversarial questions — questions whose answers aren't in the corpus at all — and see how the hallucination log changes when retrieval is guaranteed to fail. That's the hardest edge case in real RAG deployments.
- →Export the audit report as a Markdown file using Claude Code and commit it alongside your project — that way every version of your RAG corpus has a dated eval report attached, giving you a full quality history over time.