Inferensys

Prompt

Hallucinated Field Detection Assertion Prompt

A practical prompt playbook for using the Hallucinated Field Detection Assertion Prompt in production AI workflows to catch fabricated values before they reach users.
Developer doing prompt engineering on laptop, prompt variations visible on screen, casual coding session.
PROMPT PLAYBOOK

When to Use This Prompt

Defines the precise job-to-be-done for the Hallucinated Field Detection Assertion Prompt, its ideal user, required inputs, and critical boundaries.

This prompt is a precision instrument for QA leads and platform engineers who need to programmatically verify that a structured LLM output is factually anchored in a provided source document. The core job-to-be-done is not general fact-checking; it is a targeted, field-level audit that compares every value in a JSON or structured output against a single, authoritative [SOURCE_CONTEXT]. It detects fabricated names, invented statistics, unsupported dates, and claims that sound plausible but have no evidence in the source material. Use it as a deterministic gate in a CI/CD pipeline, a post-processing assertion in a RAG system, or a quality checkpoint before extracted data is ingested into a database.

The ideal user is an engineer who already has both the [SOURCE_CONTEXT] and the [TARGET_OUTPUT] in hand. This prompt assumes you are not asking the model to search the web or use external knowledge; it operates in a strict 'closed-book' mode where the source context is the only acceptable evidence. A typical implementation involves feeding a JSON object with field-value pairs and receiving a structured grounding report that flags each field as supported, unsupported, or contradicted, along with the specific evidence fragment or a null evidence marker. This is particularly valuable in regulated workflows where an unsupported claim in a generated summary or an extracted record can have compliance consequences.

Do not use this prompt when you need to evaluate the quality, style, or helpfulness of an output. It is not a general evaluator or a substitute for a human review of tone and nuance. It is also not a replacement for a retrieval system's own confidence scores; it is a post-hoc assertion on the final payload. If your source context is too large for a single context window, you must chunk it and run the assertion per chunk, or use a retrieval step to pre-select the most relevant evidence before invoking this prompt. In high-risk domains like healthcare or finance, always route unsupported findings to a human review queue rather than auto-rejecting or auto-correcting the output.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Hallucinated Field Detection Assertion Prompt delivers value and where it creates risk. Use these cards to decide if this prompt belongs in your QA pipeline or if you need a different approach.

01

Strong Fit: Structured Outputs with Source Context

Use when: You have a structured output (JSON, typed object) and the source context that was provided to the model. The prompt compares each field against the evidence to flag fabricated values. Guardrail: Always pass the exact source context used during generation—not a summary or a different retrieval result—to avoid false mismatch flags.

02

Weak Fit: Free-Text Narrative Without Field Boundaries

Avoid when: The output is unstructured prose with no explicit field schema. The assertion prompt relies on field-level comparison and cannot reliably attribute claims to fields in running text. Guardrail: Pre-process narrative outputs into extracted claim lists before running grounding checks, or use a separate claim extraction step.

03

Required Input: Field Schema with Grounding Expectations

Risk: Without a schema that defines which fields should be grounded in source context, the assertion prompt cannot distinguish between acceptable inference and hallucination. Guardrail: Provide a field-level grounding map indicating which fields require source evidence, which allow model inference, and which are purely structural.

04

Operational Risk: Source-Output Alignment Drift

Risk: If the source context format changes or the output schema evolves independently, field-level comparisons will produce false positives that erode trust in the assertion pipeline. Guardrail: Version your output schemas alongside your assertion prompts and run regression tests whenever either changes. Treat schema drift as a breaking change.

05

Pipeline Fit: Pre-Gate Before Downstream Consumption

Use when: You need an automated gate that blocks hallucinated outputs before they reach users, databases, or downstream systems. This prompt produces a structured report suitable for CI/CD pass/fail decisions. Guardrail: Set explicit thresholds for blocking versus warning. Not every unsupported field requires a hard stop—some may be acceptable with a confidence flag.

06

Not a Fit: Real-Time Streaming or Latency-Sensitive Paths

Avoid when: You need sub-second validation on streaming outputs or user-facing chat. Field-level grounding checks require a full output and source context, adding latency. Guardrail: Use this prompt in async QA pipelines, batch validation, or pre-release gates. For real-time paths, consider lighter-weight schema checks or defer grounding validation to post-hoc review.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A field-level grounding assertion prompt that compares output fields against source context to detect fabricated values.

This template is designed to be pasted directly into your assertion harness. It instructs the model to act as a strict, evidence-based auditor. The prompt takes a structured output and the source context that was supposed to ground it, then produces a field-by-field report. Each field is classified as GROUNDED, HALLUCINATED, or UNCERTAIN, with a direct evidence quote or a clear explanation of the gap. This is not a general-purpose fact-checker; it is a targeted tool for catching fabricated entities, invented numbers, and unsupported claims in structured data extracted by another LLM call.

text
You are an output validation auditor. Your task is to compare each field in the [OUTPUT_SCHEMA] of a generated response against the provided [SOURCE_CONTEXT]. You must produce a strict, field-level grounding report.

## INPUT
**Source Context:**

[SOURCE_CONTEXT]

code

**Generated Output:**
```json
[GENERATED_OUTPUT]

OUTPUT_SCHEMA

Your response must be a valid JSON object with a single key "field_checks" containing an array of objects. Each object must have the following keys:

  • "field_path": The JSON path to the field being checked (e.g., $.user.name).
  • "field_value": The exact value from the generated output.
  • "verdict": One of "GROUNDED", "HALLUCINATED", or "UNCERTAIN".
  • "evidence": If GROUNDED, a direct quote from the source context. If HALLUCINATED, a statement that the value is not present in the source. If UNCERTAIN, explain the ambiguity.

CONSTRAINTS

  • Do not infer or assume any information not explicitly present in the [SOURCE_CONTEXT].
  • A field is HALLUCINATED if its value is not directly supported by the source, even if it seems plausible.
  • A field is UNCERTAIN if the source implies the information but does not state it explicitly.
  • If the [GENERATED_OUTPUT] is not valid JSON, return a single error object: {"error": "Invalid JSON input", "detail": "..."}.
  • Do not add any text outside the JSON response.

To adapt this template, replace the placeholders with your specific data. [SOURCE_CONTEXT] should contain the raw text the original LLM was supposed to use. [GENERATED_OUTPUT] is the structured JSON you are validating. The [OUTPUT_SCHEMA] description can be a simple list of field paths to check or a full JSON Schema, depending on how you want to scope the audit. For high-risk domains like healthcare or finance, always route HALLUCINATED verdicts to a human review queue before taking any action. You can harden this further by adding a [RISK_LEVEL] parameter that adjusts the strictness of the UNCERTAIN classification.

IMPLEMENTATION TABLE

Prompt Variables

Required inputs for the Hallucinated Field Detection Assertion Prompt. Each placeholder must be populated before the prompt can reliably compare output fields against source context and produce a grounding report.

PlaceholderPurposeExampleValidation Notes

[OUTPUT_PAYLOAD]

The structured LLM output to audit for hallucinated fields

{"name": "Acme Corp", "revenue": "$12B", "ceo": "Jane Smith"}

Must be valid JSON. If parsing fails, abort and return a PARSE_ERROR verdict before grounding checks.

[SOURCE_CONTEXT]

The ground-truth evidence against which each field is validated

Acme Corp FY2024 filing: revenue $11.8B, CEO John Doe. No mention of Jane Smith.

Must be non-empty. If null or whitespace-only, mark all fields as UNVERIFIABLE with reason MISSING_CONTEXT.

[FIELD_SCHEMA]

A map of field names to expected types and nullability rules

{"name": "string|required", "revenue": "string|required", "ceo": "string|required"}

Used to determine which fields to check. If omitted, extract all top-level keys from [OUTPUT_PAYLOAD].

[GROUNDING_THRESHOLD]

Minimum confidence score for a field to be considered grounded

0.7

Float between 0.0 and 1.0. Fields below this threshold are flagged as UNSUPPORTED. Default to 0.5 if not provided.

[ALLOWED_EXTRAPOLATION]

Whether to permit reasonable inferences not explicitly stated in source context

Boolean. If true, fields with strong contextual support but no exact match may pass. If false, require explicit evidence for every claim.

[OUTPUT_FORMAT]

Desired structure for the grounding report

json

Accepted values: json, markdown_table. Defaults to json. Report must include field_name, claimed_value, grounding_status, evidence_found, confidence_score per field.

[STRICT_MODE]

Whether to fail on any ungrounded field or return a full report

Boolean. If true, return a single HALLUCINATION_DETECTED verdict on first unsupported field. If false, return the complete field-level report regardless of findings.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the Hallucinated Field Detection Assertion Prompt into a CI/CD pipeline or production QA workflow.

This prompt is designed to be called programmatically as a validation gate, not as a one-off chat interaction. The typical integration point is immediately after an LLM generates a structured output that must be grounded in source context. You pass the original source context, the generated output, and a field-level schema into this assertion prompt, and it returns a structured grounding report. The report is machine-readable and should be parsed to decide whether to accept, flag, or reject the upstream output.

In a CI/CD pipeline, wrap this prompt in a test harness that calls your primary generation endpoint, collects the output, and then calls this assertion prompt with the same source context. Parse the JSON response and check the overall_verdict field. If overall_verdict is FAIL, block the pipeline or route the output for human review. For production systems, implement a retry loop: if the assertion fails, feed the violation details back to the generation model as correction instructions, regenerate, and re-assert. Limit retries to 3 attempts before escalating. Log every assertion result—including the source context hash, output hash, verdict, and per-field evidence gaps—for auditability and drift detection over time.

Model choice matters here. Use a model with strong instruction-following and JSON output reliability, such as gpt-4o or claude-3-5-sonnet. Avoid smaller or older models that may hallucinate the assertion itself. Set temperature=0 to maximize determinism. Validate the assertion output against a JSON Schema before trusting the verdict; if the assertion prompt itself returns malformed JSON, treat it as an infrastructure failure and escalate. For high-stakes domains like healthcare or finance, never auto-accept a PASS verdict without sampling a percentage of assertions for human review. The assertion prompt reduces hallucination risk but does not eliminate it—treat it as a strong filter, not a guarantee.

IMPLEMENTATION TABLE

Expected Output Contract

Field-level contract for the hallucinated field detection assertion prompt. Use this table to parse and validate the assertion output before routing to CI/CD gates or human review queues.

Field or ElementType or FormatRequiredValidation Rule

verdict

string enum: pass | fail | review

Must be one of the three allowed enum values. Fail if missing or out-of-set.

overall_confidence

number (0.0–1.0)

Must be a float between 0 and 1 inclusive. Fail if non-numeric or out of range.

fields_checked

array of objects

Must be a non-empty array. Each element must contain the field_name key. Fail if empty or missing.

fields_checked[].field_name

string

Must match a field name present in the [OUTPUT_SCHEMA] provided to the prompt. Fail if unrecognized field.

fields_checked[].grounding_status

string enum: grounded | hallucinated | uncertain | not_applicable

Must be one of the four allowed enum values. Fail if missing or out-of-set.

fields_checked[].evidence_reference

string or null

Must be a non-empty string when grounding_status is grounded or hallucinated. Null allowed for uncertain or not_applicable. Fail if evidence is missing for a grounded/hallucinated claim.

fields_checked[].explanation

string

Must be a non-empty string explaining the grounding determination. Fail if empty or missing.

hallucinated_fields_summary

array of strings

Must list field names with hallucinated status. Empty array is valid when no hallucinations detected. Fail if it contains fields not marked hallucinated in fields_checked.

PRACTICAL GUARDRAILS

Common Failure Modes

When validating LLM outputs for hallucinated fields, these failures surface first. Each card identifies a specific breakdown and the guardrail that catches it before it reaches production.

01

Invented Entity Names

What to watch: The model fabricates plausible-sounding names, IDs, or identifiers that do not appear anywhere in the provided source context. This is especially common with person names, product codes, and reference numbers. Guardrail: Implement an exact-match or fuzzy-match check that requires every extracted entity value to have a corresponding substring in the source document. Flag any field value with zero source matches as a grounding violation.

02

Fabricated Numerical Values

What to watch: The model generates specific numbers, dates, percentages, or monetary amounts that are not supported by the source. These often look reasonable but are complete inventions. Guardrail: Require numeric fields to be traceable to a source span. Use a numeric proximity check—if the output value differs from any source number by more than a configurable epsilon, escalate for human review rather than silently accepting.

03

Over-Confident Missing-Field Synthesis

What to watch: When the source lacks information for a requested field, the model fills the gap with a confident-sounding answer instead of returning null or an explicit absence marker. Guardrail: Add a pre-check that scans the source for field-relevant keywords before extraction. If no supporting evidence exists, enforce a null output. Pair this with a nullability schema that defines which fields are allowed to be empty and which must have evidence.

04

Source-Context Boundary Bleed

What to watch: The model pulls in knowledge from its training data that sounds relevant but was never provided in the source context. This is especially dangerous in regulated domains where only approved documents should inform outputs. Guardrail: Use a strict grounding assertion that compares each output claim against the provided context only—not against general knowledge. Log any claim that cannot be anchored to a specific source passage as ungrounded and block it from downstream systems.

05

False Negative Grounding Failures

What to watch: The assertion prompt itself incorrectly flags a valid extraction as hallucinated because the source expresses the information differently—through synonyms, paraphrases, or implicit relationships. Guardrail: Calibrate your grounding checker with a golden dataset of known-valid extractions. Measure false positive rates across paraphrased sources. Add a semantic similarity threshold as a secondary check before flagging, and log borderline cases for manual review.

06

Multi-Field Cross-Hallucination

What to watch: Individual fields pass grounding checks in isolation, but the combination of fields creates a fabricated relationship. For example, a correct name and a correct date are paired to invent an association that does not exist in the source. Guardrail: Add cross-field assertion rules that check relational integrity. If field A and field B are both grounded, verify that their co-occurrence is also supported by a single source span or explicitly linked passage. Flag unsupported pairings.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to test the hallucinated field detection assertion prompt before shipping. Each criterion defines a pass standard, a failure signal, and a concrete test method.

CriterionPass StandardFailure SignalTest Method

Supported Field Detection

All fields with direct source evidence are correctly classified as SUPPORTED with exact citation spans.

A field with clear source evidence is classified as UNSUPPORTED or HALLUCINATED.

Run against a golden dataset of 20+ output records with known source-to-field mappings. Measure precision and recall per field.

Hallucinated Field Detection

All fabricated values not present in [SOURCE_CONTEXT] are classified as HALLUCINATED with evidence gap explanation.

A fabricated value is classified as SUPPORTED or UNSUPPORTED instead of HALLUCINATED.

Inject known fabricated fields into test outputs. Verify the prompt flags every injected hallucination without false negatives.

Missing Evidence Classification

Fields where [SOURCE_CONTEXT] is silent are classified as UNSUPPORTED, not HALLUCINATED.

A field absent from source context is incorrectly labeled HALLUCINATED instead of UNSUPPORTED.

Test with outputs containing fields outside source scope. Confirm UNSUPPORTED label and absence of fabrication accusation.

Citation Span Accuracy

Every SUPPORTED classification includes a citation span that exactly matches the source text supporting the field value.

Citation span points to wrong source location, is truncated, or is missing for a SUPPORTED field.

Spot-check 30 citation spans against source documents. Verify character-offset or quote-exactness match.

Field Coverage Completeness

Every field in [OUTPUT_SCHEMA] appears in the grounding report with a classification.

One or more output fields are silently omitted from the grounding report.

Parse the grounding report JSON. Assert field count equals the number of fields in the input output schema.

Confidence Score Calibration

Confidence scores for SUPPORTED fields are >= 0.8 when evidence is unambiguous. Scores for HALLUCINATED fields are <= 0.3.

A clearly hallucinated field receives confidence >= 0.7, or a clearly supported field receives confidence <= 0.4.

Bin confidence scores by ground-truth label. Measure expected calibration gap per classification bucket.

Null and Empty Field Handling

Null or empty fields in the output are classified as NULL_OR_EMPTY and excluded from hallucination checks.

A null field is incorrectly classified as HALLUCINATED or triggers a false positive.

Include outputs with intentional nulls and empty strings. Verify NULL_OR_EMPTY classification and no hallucination flag.

Adversarial Near-Match Detection

Values that closely resemble source text but contain altered numbers, names, or dates are classified as HALLUCINATED.

A subtly altered value passes as SUPPORTED because it shares substrings with source text.

Create test cases with near-match fabrications: changed digits, swapped entity names, shifted dates. Verify detection.

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Start with the base prompt and a single source document. Use a lightweight JSON output without strict schema enforcement. Focus on detecting obviously fabricated fields—names, dates, amounts that don't appear anywhere in the source.

code
Compare each field in [OUTPUT_JSON] against [SOURCE_TEXT].
Flag any field whose value cannot be found or inferred from the source.
Return: { "fields": [{"field_path": "...", "status": "FOUND|NOT_FOUND|PARTIAL", "evidence": "..."}] }

Watch for

  • Paraphrased values flagged as NOT_FOUND when they're semantically present
  • Missing schema checks letting malformed JSON through
  • Overly strict string matching rejecting legitimate rephrasing
Prasad Kumkar

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.