This prompt is a post-generation audit tool for compliance-sensitive AI applications that produce cited answers. Its primary job is to verify that every citation, reference, and source attribution in a generated text can be traced back to a provided retrieval corpus. The ideal user is an AI engineer or platform builder integrating this check into a RAG pipeline, a compliance officer validating outputs before they reach end users, or a QA lead building automated evaluation harnesses. You need two things to use this prompt: the generated text containing citations, and the complete set of source documents or passage IDs that were available during generation. Without both, the verification cannot proceed.
Prompt
Hallucinated Source Detection Prompt

When to Use This Prompt
Defines the job-to-be-done, ideal user, required context, and when not to use this prompt for hallucinated source detection.
Use this prompt when fabricated citations create regulatory risk, when retrieval failures in your RAG pipeline could produce plausible-sounding but non-existent references, and when user trust depends on verifiable source provenance. It belongs in workflows where a single hallucinated citation can cause a compliance violation, a customer escalation, or a loss of credibility. The prompt returns a structured verdict for each citation—verified, hallucinated, or ambiguous—along with supporting evidence and a recommended action. This output can be wired directly into an automated gate that blocks responses with hallucinated sources or routes them for human review.
Do not use this prompt as a generation step. It is not designed to produce answers or fix citations; it only audits them. Do not use it when your application does not have a defined retrieval corpus to cross-reference against—the prompt cannot detect hallucination without ground truth evidence. Do not use it for real-time streaming responses where citations are still being formed. And do not treat it as a replacement for retrieval quality improvements; if your retriever consistently fails to surface relevant documents, this prompt will correctly flag the resulting citations as unsupported, but the root cause is retrieval failure, not citation fabrication. Pair this prompt with retrieval evaluation and retry logic before relying on it as your sole hallucination guard.
Use Case Fit
Where the Hallucinated Source Detection Prompt works, where it fails, and the operational prerequisites for production use.
Good Fit: Compliance-Critical RAG Pipelines
Use when: generated answers must be traceable to a known, auditable corpus. Guardrail: always run detection before the answer reaches the user; block or flag outputs with unverifiable citations.
Bad Fit: Open-Ended Creative Generation
Avoid when: the model is expected to invent or synthesize beyond a fixed retrieval set. Guardrail: disable hallucination detection for brainstorming or drafting modes where provenance is not required.
Required Input: Retrieval Corpus Snapshot
Risk: detection cannot work without the exact source texts the model was shown. Guardrail: pass the full, unmodified retrieved passages alongside the generated answer; never rely on the model's memory of the corpus.
Operational Risk: Latency and Cost Amplification
Risk: adding a detection pass doubles token usage and latency for every answer. Guardrail: use a smaller, faster model for the detection step and gate it behind a sampling strategy or confidence threshold.
Operational Risk: False Positives on Paraphrased Evidence
Risk: the detector may flag legitimate paraphrases as hallucinations. Guardrail: calibrate detection prompts with few-shot examples of acceptable paraphrase vs. fabrication; log all flags for human audit.
Bad Fit: Real-Time Conversational Agents
Avoid when: sub-second response times are required and the retrieval corpus is static. Guardrail: pre-verify the corpus integrity offline and use citation post-generation checks only for async or high-stakes turns.
Copy-Ready Prompt Template
A ready-to-use prompt for detecting fabricated citations and non-existent sources in AI-generated text.
This prompt template is designed to be dropped directly into your validation harness. It instructs the model to act as a provenance auditor, cross-referencing every citation in a generated text against a provided list of verified source identifiers. The core job is to flag any reference that cannot be traced back to the retrieval corpus, distinguishing between a true hallucination and a minor formatting error. Before integrating, ensure your pipeline can supply the [VERIFIED_SOURCE_IDS] from your document store or vector database metadata.
codeYou are a strict provenance auditor. Your task is to analyze the provided [GENERATED_TEXT] and identify any cited sources that are fabricated, non-existent, or cannot be matched to the [VERIFIED_SOURCE_IDS] list. # INPUTS - [GENERATED_TEXT]: The AI-generated answer containing inline citations. - [VERIFIED_SOURCE_IDS]: A JSON array of unique identifiers for every document in the retrieval corpus. Example: ["doc_123", "doc_456.pdf", "ref_789"] - [CITATION_FORMAT]: A description of the citation format used in the text (e.g., "[doc_id]", "(Author, Year)", "footnote number"). # TASK 1. Extract every distinct citation from [GENERATED_TEXT] based on [CITATION_FORMAT]. 2. For each extracted citation, attempt to match it to an entry in [VERIFIED_SOURCE_IDS]. Use fuzzy matching for minor formatting differences (e.g., "doc_123" vs "DOC-123") but do not guess. 3. Classify each citation into one of three categories: - **VERIFIED**: The citation matches a known source ID. - **HALLUCINATED**: The citation does not match any known source ID and appears fabricated. - **FORMAT_ERROR**: The citation is a close match to a known source ID but has a typo or formatting inconsistency. 4. For every HALLUCINATED or FORMAT_ERROR citation, quote the specific sentence in [GENERATED_TEXT] where it appears. # OUTPUT_SCHEMA Return a single JSON object with the following structure: { "audit_result": { "total_citations_found": <integer>, "verified_count": <integer>, "hallucinated_count": <integer>, "format_error_count": <integer>, "flagged_citations": [ { "extracted_citation_text": "<string>", "status": "HALLUCINATED" | "FORMAT_ERROR", "context_sentence": "<string>", "suggested_correction": "<string or null>" } ] } } # CONSTRAINTS - Do not invent source IDs. Only match against [VERIFIED_SOURCE_IDS]. - If a citation is ambiguous, flag it as HALLUCINATED. - Output only the JSON object. No markdown fences or explanatory text.
To adapt this template, replace the placeholders with your application's specific data structures. The [VERIFIED_SOURCE_IDS] list should be dynamically generated from your retrieval step's metadata. For high-stakes compliance applications, the output of this prompt should not be the final step. Pipe the flagged_citations array into a human review queue or a secondary verification tool that can perform a live lookup against the source database. This prompt is a detection mechanism, not a correction mechanism; pair it with a 'Citation Insertion Repair' or 'Answer Regeneration' prompt to close the loop.
Prompt Variables
Required inputs for the Hallucinated Source Detection Prompt. Each placeholder must be populated before the prompt is sent. Validation checks prevent silent failures from missing or malformed inputs.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[GENERATED_TEXT] | The model output to audit for hallucinated sources | According to Smith (2024), the market grew 15%. | Required. Must be non-empty string. Reject if only whitespace or under 20 characters. Check for presence of citation-like patterns before running full detection. |
[RETRIEVAL_CORPUS] | The set of source documents the model was allowed to cite | ["doc_1": "Market analysis Q3 2024...", "doc_2": "Industry report..."] | Required. Must be a non-empty array of document objects with id and content fields. Validate schema before prompt assembly. Reject if corpus size is zero. |
[CITATION_FORMAT] | Expected citation pattern to search for in generated text | "Author (Year)" or "[1]" or "§ 12.3" | Required. Must be a non-empty string describing the format. Use enum validation against supported formats: author-year, numeric-bracket, section-reference, custom-regex. |
[SOURCE_IDENTIFIER_MAP] | Mapping from citation strings to corpus document IDs | {"Smith (2024)": "doc_1", "Jones (2023)": "doc_2"} | Optional. If null, the prompt must extract identifiers from [CITATION_FORMAT] and match against corpus. If provided, validate that all keys match the citation format pattern and all values exist in [RETRIEVAL_CORPUS]. |
[CONFIDENCE_THRESHOLD] | Minimum confidence score for a citation to be considered verified | 0.85 | Required. Must be a float between 0.0 and 1.0. Default 0.80 if not specified. Reject values below 0.50 as too permissive. Log warning if threshold exceeds 0.95. |
[OUTPUT_SCHEMA] | Expected structure for the detection report | {"claim": string, "citation": string, "source_id": string|null, "match_found": boolean, "confidence": float, "explanation": string} | Required. Must be a valid JSON Schema object. Validate parseability before prompt assembly. Reject schemas missing required fields: claim, citation, match_found, confidence. |
[ESCALATION_POLICY] | Rules for when to escalate to human review | "escalate_if_any_hallucination": true, "escalate_if_confidence_below": 0.70 | Required. Must be a valid JSON object with at least one escalation condition. Validate that conditions reference fields present in [OUTPUT_SCHEMA]. Reject if no conditions defined. |
[MAX_RETRIEVAL_RETRIES] | Number of re-retrieval attempts allowed before final escalation | 3 | Optional. Integer between 0 and 5. Default 2. Set to 0 to disable retry and escalate immediately on first detection failure. Validate as non-negative integer. |
Implementation Harness Notes
How to wire the hallucinated source detection prompt into a production validation pipeline with retries, logging, and human review gates.
This prompt is designed to sit inside a post-generation validation harness, not as a standalone chat interaction. After your primary system produces a cited answer, pass both the generated text and the full retrieval context into this prompt. The harness should treat the prompt's output as a structured verdict—not a suggestion—and use it to decide whether the answer can be served to the user, requires regeneration, or must be escalated for human review.
Wire the prompt into a validation loop with a configurable retry budget. On a verdict: FAIL, extract the list of hallucinated sources and feed them back into your answer-generation prompt as negative constraints—for example, 'Do not cite any of the following fabricated sources: [LIST].' Retry up to [MAX_RETRIES] times, typically 2–3. After the budget is exhausted, route the answer to a human review queue with the hallucination report attached. Log every invocation: the input context hash, the model and version used, the verdict, the list of flagged sources, and the retry count. This trace is essential for debugging retrieval gaps and for audit evidence in compliance-sensitive domains.
Model choice matters here. Use a model with strong instruction-following and structured output capabilities—GPT-4o, Claude 3.5 Sonnet, or equivalent. Avoid smaller or older models that may conflate plausible-sounding source names with actual retrieval results. If your retrieval corpus is large, consider truncating the provided context to the top-N passages actually used in the answer to keep the prompt within token limits. Validate the output schema strictly: if the JSON is malformed or missing required fields, treat it as a FAIL and increment the retry counter. Never serve an answer that hasn't passed this check to a user in a compliance-sensitive workflow.
For high-stakes applications, add a human-in-the-loop gate after the first FAIL verdict. Present the reviewer with the original answer, the flagged sources, and the retrieval context side by side. The reviewer can confirm the hallucination, override a false positive, or mark the source as legitimate but poorly formatted. Feed these human decisions back into your eval dataset to improve the prompt's precision over time. Avoid using this prompt as the sole defense in regulated domains—pair it with retrieval-audit logging, citation-mandatory generation prompts, and periodic manual audits of served answers.
Expected Output Contract
Fields, format, and validation rules for the JSON response returned by the Hallucinated Source Detection Prompt. Use this contract to parse, validate, and route the model's output in your application harness.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
verification_id | string (UUID v4) | Must be a valid UUID v4 string generated by the model for traceability. Reject if missing or malformed. | |
claim_id | string | Must match the [CLAIM_ID] provided in the input. Reject if missing or mismatched. | |
claim_text | string | Must be a non-empty string. Reject if null, empty, or whitespace-only. | |
source_passage_id | string | Must match a [PASSAGE_ID] from the provided [RETRIEVED_SOURCES] array. Reject if missing or not found in the source set. | |
verification_status | enum: VERIFIED | HALLUCINATED | UNCERTAIN | UNVERIFIABLE | Must be one of the four allowed enum values. Reject any other value. UNCERTAIN requires a non-null uncertainty_reason. | |
source_text_match | string or null | If VERIFIED, must contain the exact substring from the source that supports the claim. If HALLUCINATED, must be null. If UNCERTAIN, may be null or partial match. | |
discrepancy_detail | string or null | Required if verification_status is HALLUCINATED. Must describe the specific mismatch between claim and source. Null allowed for VERIFIED or UNVERIFIABLE. | |
confidence_score | number (0.0 to 1.0) | Must be a float between 0.0 and 1.0 inclusive. Reject if out of range. Scores below [CONFIDENCE_THRESHOLD] should trigger human review. |
Common Failure Modes
What breaks first when detecting hallucinated sources and how to guard against it in production.
Plausible Fabrication
What to watch: The model generates a citation that looks real—real author name, real journal, plausible title—but the paper or document does not exist. This is the most dangerous failure mode because it passes casual human review. Guardrail: Require every citation to be matched against a retrieval corpus or verified database. Implement a strict source_exists boolean check before accepting any citation. If the source cannot be located in the ground-truth set, flag it as fabricated and trigger regeneration with a mandatory evidence constraint.
Source-Content Mismatch
What to watch: The cited source exists, but the claim attributed to it is not actually present in that document. The model has correctly identified a real source but incorrectly mapped content to it. Guardrail: Implement a claim-to-source alignment verification step. Extract each factual claim, retrieve the cited passage, and run a textual entailment or semantic similarity check. If the alignment score falls below a threshold, flag the citation as mismatched and require regeneration with the actual source content provided as context.
Citation Drift Across Long Outputs
What to watch: In multi-paragraph answers, early citations are accurate but later citations drift—the model starts attributing claims to sources cited earlier even when those sources don't support the new claims. This is common in long-form generation where attention dilutes over distance. Guardrail: Segment long outputs by paragraph or claim group and verify each citation block independently against its referenced source. Implement a drift distance metric that measures how far a citation's content diverges from its source passage. Re-anchor drifted citations before returning the final output.
Over-Citation and Source Padding
What to watch: The model cites sources that are tangentially related or completely irrelevant to pad the citation count and appear more grounded. This creates an illusion of thoroughness while masking unsupported claims. Guardrail: Score each citation for relevance to the specific claim it supports, not just topical overlap with the answer. Set a minimum relevance threshold. Remove citations that don't meet the threshold and regenerate the answer with only genuinely supportive sources. Flag answers where citation count drops significantly after filtering.
Boundary Error in Quoted Text
What to watch: The model presents text as a direct quote but alters wording, truncates context, or merges sentences from different parts of the source. This misrepresents what the source actually says and creates compliance risk in legal, medical, or financial contexts. Guardrail: Run a quote fidelity check that compares the quoted string against the source passage using exact or fuzzy string matching. Flag any quote with less than 95% character-level match. Require verbatim quotes or explicit paraphrase markers—never allow paraphrased text inside quotation marks.
Retrieval Corpus Blind Spots
What to watch: The model correctly identifies that a claim needs a citation but the retrieval system failed to return the relevant document. The model then either fabricates a source or incorrectly attributes the claim to a retrieved but irrelevant document. Guardrail: Before running hallucination detection, validate that the retrieval corpus actually contains the necessary evidence. If the corpus has gaps, the system should abstain or expand retrieval rather than forcing a citation. Implement a pre-check that estimates evidence sufficiency before generation begins.
Evaluation Rubric
Criteria for evaluating the Hallucinated Source Detection Prompt's output before shipping. Use these tests to catch fabricated citations, non-existent sources, and untraceable attributions.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Source Existence Check | Every cited source title, author, or identifier is verified as present in the retrieval corpus | Output lists a source that cannot be matched to any document in the provided context | Parse all [CITATION] markers from output; for each, attempt exact and fuzzy match against [RETRIEVAL_CORPUS] metadata |
Provenance Traceability | Every claim-to-source mapping includes a retrievable passage ID or offset that resolves to the exact text | A claim is attributed to a source but the passage ID is missing, null, or points to a non-existent section | Extract all [SOURCE_ID] references; validate each resolves to a valid passage in the source document index |
Fabricated Detail Detection | No invented DOIs, URLs, page numbers, or publication dates appear that are absent from the source metadata | Output contains a DOI, URL, or date string that does not appear in any provided source record | Regex-scan output for DOI/URL/date patterns; cross-reference each against [SOURCE_METADATA] fields |
Quote Fidelity | Any quoted text in the output matches the source passage verbatim, including punctuation and whitespace | A quoted string differs from the source text by more than 2 characters or is entirely absent from the source | Extract all quoted strings; perform exact substring search in the referenced source passage; flag any edit distance > 2 |
Attribution Accuracy | Every citation marker is placed adjacent to the claim it supports, not on an unrelated sentence | A citation appears at the end of a paragraph but the preceding claims are not supported by that source | For each [CITATION], check if the nearest preceding claim has a semantic similarity score > 0.7 with the cited passage |
Hallucination Confidence Flag | Output includes a confidence score for each citation, and any score below [CONFIDENCE_THRESHOLD] is flagged for review | A citation with low semantic similarity to its claim is assigned a high confidence score or no score at all | Compute cosine similarity between claim embedding and source passage embedding; verify that [CONFIDENCE_SCORE] correlates with similarity (r > 0.6) |
Abstention on Unsupported Claims | Claims that cannot be traced to any source are either removed or explicitly marked as unsupported | Output contains a factual assertion with no citation and no unsupported-claim disclaimer | Compare count of factual claims extracted via NLI model to count of citations; flag any claim with zero supporting citations and no [UNSUPPORTED] tag |
Retry Escalation Compliance | After [MAX_RETRIES] attempts, the system stops retrying and returns a structured escalation payload | Output continues to regenerate with new fabricated citations after exceeding the retry budget | Run the prompt in a loop with a counter; assert that after [MAX_RETRIES] iterations the output matches [ESCALATION_SCHEMA] and contains no new citations |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Start with the base prompt and a small set of known-good and known-hallucinated source lists. Use a frontier model with no additional tooling. Focus on getting the detection logic right before adding schema enforcement.
codeYou are a source verification auditor. Given a list of [CLAIMS] and a list of [AVAILABLE_SOURCES], flag any claim that references a source not present in the available sources list. For each flagged claim, explain why it cannot be verified. [CLAIMS] [AVAILABLE_SOURCES]
Watch for
- The model treating partial matches as full matches
- Over-flagging when source titles are paraphrased rather than fabricated
- No structured output format, making downstream parsing fragile

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us