Inferensys

Prompt

Extra Hallucinated Field Removal Prompt Template

A practical prompt playbook for using the Extra Hallucinated Field Removal Prompt Template in production AI workflows to strip invented fields and log removals.
Developer doing prompt engineering on laptop, prompt variations visible on screen, casual coding session.
PROMPT PLAYBOOK

When to Use This Prompt

Define the job, reader, and constraints for removing hallucinated fields from model outputs before they reach downstream systems.

This prompt is for API developers and integration engineers who receive model outputs containing invented fields not present in the target schema. The job-to-be-done is stripping extra fields that have no source grounding while preserving legitimate data and logging removals for observability. Use this when your model consistently adds plausible-sounding but unsupported fields—like inventing a customer_since date when only name and email were requested—and you need a programmatic cleanup step before the payload hits a database, API gateway, or user-facing surface.

This prompt is not a schema validator or a type coercion tool. It assumes the input is structurally valid JSON and that you have a defined target schema to compare against. Do not use this prompt when the model output is malformed JSON (use the JSON Structure Repair Prompt Template instead), when required fields are missing (use Missing Required Field Injection), or when field names are semantically correct but use wrong casing or near-miss labels (use Wrong Field Name Mapping). This prompt is specifically for removing fields that should not exist at all in the output.

The ideal user has a target schema—either as a JSON Schema document, a list of allowed field names, or a reference object—and needs a reliable, logged, and evaluable removal step. Before deploying this prompt, ensure you have a way to diff the input and output to confirm that only hallucinated fields were removed and that no legitimate fields were stripped. In high-stakes pipelines where false-positive removal could drop critical data, route uncertain cases to a human review queue rather than silently deleting fields.

PRACTICAL GUARDRAILS

Use Case Fit

Where this prompt works, where it fails, and what inputs it assumes for reliable field removal.

01

Good Fit: API Response Sanitization

Use when: A model generates JSON for an API endpoint and invents fields not in the OpenAPI contract. Guardrail: Run this prompt as a post-processing step before the response hits the serializer, logging all removed fields for observability.

02

Bad Fit: Semantic Content Filtering

Avoid when: You need to decide if a field's value is hallucinated, not whether the field itself is allowed. Risk: This prompt removes entire keys based on schema membership, not truthfulness. Use a factuality eval for value-level hallucination.

03

Required Input: Authoritative Field Allowlist

What to watch: Without an explicit, machine-readable list of permitted fields, the prompt cannot distinguish invention from legitimate output. Guardrail: Provide the allowlist as a JSON Schema, OpenAPI spec fragment, or explicit array of field names in the prompt context.

04

Operational Risk: False-Positive Removal

What to watch: A legitimate field may be removed if its name is missing from the allowlist due to a documentation gap. Guardrail: Implement a diff log that records every removed field and its value. Route removals to a review queue if the output is used in a high-stakes downstream system.

05

Operational Risk: Nested Object Blindness

What to watch: A simple top-level field check may miss hallucinated fields nested inside legitimate objects. Guardrail: The prompt must recursively validate all nested objects against the schema. Include a depth limit to prevent infinite recursion on circular references.

06

Variant: Audit-Only Mode

Use when: You are not yet ready to strip fields automatically in production. Guardrail: Modify the prompt to output a structured audit report (field name, path, value sample) instead of the cleaned object. This lets you measure the hallucination rate before enabling removal.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt template with square-bracket placeholders for stripping extra hallucinated fields from model outputs.

This template is designed to be copied directly into your application code or prompt management system. It instructs the model to act as a strict schema filter: remove any field not explicitly defined in the provided target schema, log what was removed and why, and return only the cleaned payload. The square-bracket placeholders must be replaced with your actual schema, input data, and operational constraints before use.

text
You are a strict output sanitizer. Your only job is to remove extra hallucinated fields from a model-generated payload.

**Target Schema (canonical field names only):**
[OUTPUT_SCHEMA]

**Payload to clean:**
[INPUT]

**Instructions:**
1. Compare every field in the payload against the Target Schema.
2. If a field exists in the payload but NOT in the Target Schema, remove it entirely.
3. Do not rename, retype, or restructure any field. Only remove extra fields.
4. For every field you remove, record it in a `removals` array with:
   - `field`: the full path of the removed field (use dot notation for nested fields, e.g., `address.line2`)
   - `reason`: a brief explanation (e.g., "not present in target schema")
5. Return a JSON object with exactly two keys:
   - `cleaned_output`: the payload with only schema-approved fields remaining
   - `removals`: the array of removal records
6. If no fields need removal, return the original payload in `cleaned_output` and an empty `removals` array.
7. Do not add commentary, markdown fences, or extra text outside the JSON object.

**Example:**
Target Schema: {"name": "string", "email": "string"}
Input: {"name": "Alice", "email": "alice@example.com", "age": 30, "phone": "555-0100"}
Output:
{
  "cleaned_output": {"name": "Alice", "email": "alice@example.com"},
  "removals": [
    {"field": "age", "reason": "not present in target schema"},
    {"field": "phone", "reason": "not present in target schema"}
  ]
}

**Risk Level:** [RISK_LEVEL]
**Additional Constraints:** [CONSTRAINTS]

To adapt this template, replace [OUTPUT_SCHEMA] with your canonical schema definition—either as a JSON Schema object, a TypeScript interface, or a simple key-type map. Replace [INPUT] with the raw model output you need to clean. Set [RISK_LEVEL] to guide removal aggressiveness: for high-risk domains like healthcare or finance, add a constraint requiring human review of all removals before the cleaned output is accepted. Use [CONSTRAINTS] to inject domain-specific rules, such as "preserve fields prefixed with meta_ even if not in schema" or "escalate removals exceeding 20% of total fields for human review." Always validate the returned cleaned_output against your schema in application code before ingestion—do not rely solely on the model's removal judgment.

IMPLEMENTATION TABLE

Prompt Variables

Required inputs for the Extra Hallucinated Field Removal Prompt Template. Provide these variables to reliably strip invented fields while preserving legitimate data and generating an audit log.

PlaceholderPurposeExampleValidation Notes

[MODEL_OUTPUT]

The raw JSON or structured object from the model that may contain hallucinated fields

{"name": "Acme", "revenue": 500, "mood": "optimistic"}

Must be valid parseable JSON. If unparseable, route to JSON Structure Repair Prompt Template first.

[TARGET_SCHEMA]

The authoritative list of allowed field names, types, and required flags

{"fields": [{"name": "name", "type": "string", "required": true}, {"name": "revenue", "type": "number", "required": false}]}

Schema must be a complete JSON object with a fields array. Missing fields will cause false-positive removals.

[SOURCE_GROUNDING]

The original input text or context the model was supposed to use, for cross-referencing field provenance

The Q3 earnings report for Acme Corp shows revenue of $500M.

Required for evidence-based removal decisions. If null, the prompt falls back to schema-only removal with a logged warning.

[REMOVAL_LOG_SCHEMA]

The output structure for logging which fields were removed and why

{"removed_fields": [{"field": "mood", "reason": "not_in_schema", "value": "optimistic"}]}

Must define an array of removal records. Each record requires field name, reason code, and original value for auditability.

[CONFIDENCE_THRESHOLD]

Minimum confidence score for keeping a field when schema match is ambiguous

0.85

Float between 0.0 and 1.0. Fields below threshold are flagged for human review rather than silently removed. Default 0.80 if not provided.

[HUMAN_REVIEW_QUEUE]

Endpoint or identifier for routing ambiguous removal decisions to a human reviewer

review_queue: schema_field_disputes

Required when confidence threshold is used. Null allowed if fully automated removal is acceptable, but logged as a risk.

[OUTPUT_SCHEMA]

The exact structure the cleaned output must conform to, including field order and nesting

{"type": "object", "properties": {"name": {"type": "string"}, "revenue": {"type": "number"}}, "required": ["name"]}

Must match TARGET_SCHEMA. Used to validate the final output before returning. Mismatch triggers a retry or escalation.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the hallucinated field removal prompt into an API, validation, retry, logging, and human-review workflow.

This prompt is designed to sit in a post-generation repair loop—after the primary model produces an output but before that output reaches a downstream consumer, database, or user. The harness must receive the original model output, the canonical target schema, and any source grounding evidence as inputs. The prompt returns a cleaned payload and a removal log. Do not call this prompt on outputs that already pass schema validation; it is a repair step, not a primary generation step.

Validation gate: Before calling the prompt, validate the original output against the target schema. If the output already conforms, skip this prompt entirely. After the prompt returns, validate the cleaned output against the same schema. If validation still fails, log the failure and route to a human review queue—do not retry more than twice without changing the prompt or schema. Retry logic: On the first failure, retry once with the same inputs. If the second attempt also fails, escalate. Never loop indefinitely on hallucinated-field removal; the model may be inventing fields because the schema is ambiguous or the source evidence is insufficient.

Logging and observability: Capture the removed_fields array from the prompt output and attach it to your trace. Log the original field count, the removed field count, and the final field count as metrics. This lets you monitor hallucination rates over time and detect schema drift. Human review trigger: If any removed field's name plausibly matches a legitimate field not in the schema (e.g., customer_email removed when email is expected), flag for human review. This prevents false-positive removal of fields that should have been mapped rather than stripped.

Model choice: Use a fast, instruction-following model for this task (e.g., GPT-4o-mini, Claude Haiku, or a fine-tuned small model). The task is structural, not creative. Tool integration: If your system uses a schema registry or API spec as the source of truth, pass the schema definition directly into the [TARGET_SCHEMA] placeholder rather than a human-written summary. This reduces ambiguity. Eval harness: Before deploying, run this prompt against a golden dataset of outputs with known hallucinated fields. Measure precision (did it remove only hallucinated fields?) and recall (did it remove all hallucinated fields?). A recall below 95% means hallucinated fields are leaking downstream; a precision below 95% means legitimate fields are being stripped.

What to avoid: Do not use this prompt as a substitute for proper schema enforcement in your primary generation prompt. If hallucinated fields are frequent, fix the upstream prompt or add structured output constraints first. This prompt is a safety net, not a design pattern. Also avoid running this prompt on streaming outputs mid-stream; assemble the full output first, then repair.

IMPLEMENTATION TABLE

Expected Output Contract

Fields, format, and validation rules for the cleaned payload and removal log returned by the Extra Hallucinated Field Removal prompt.

Field or ElementType or FormatRequiredValidation Rule

cleaned_output

object

Must be valid JSON. Must contain only fields present in [ALLOWED_FIELD_LIST]. Must not contain any field listed in removal_log.field_name.

removal_log

array

Must be a JSON array. Each element must be an object with field_name and removal_reason. Array must be empty if no fields were removed.

removal_log[].field_name

string

Must match the exact key name removed from the original output. Must not be present in [ALLOWED_FIELD_LIST].

removal_log[].removal_reason

string

Must be one of the allowed enum values: 'not_in_schema', 'no_source_grounding', 'deprecated_field', or 'unknown_origin'. Must not be empty or null.

removal_log[].original_value

string or null

If present, must be a JSON-encoded string representation of the removed value. If null, the field was empty or value could not be serialized.

cleaned_output.[any_field]

per [ALLOWED_FIELD_LIST] schema

Each field in cleaned_output must match the type, format, and constraints defined in [ALLOWED_FIELD_LIST]. No extra fields permitted.

_metadata.processing_timestamp

ISO 8601 string

If present, must be a valid UTC timestamp in ISO 8601 format. Used for audit trail and observability.

_metadata.fields_removed_count

integer

If present, must equal removal_log.length. Must be >= 0. Used for quick monitoring without parsing the full log array.

PRACTICAL GUARDRAILS

Common Failure Modes

What breaks first when stripping hallucinated fields and how to prevent false-positive removal of legitimate data.

01

False-Positive Removal of Optional Fields

What to watch: The prompt aggressively removes fields not explicitly listed in the target schema, deleting optional or dynamically named fields that downstream systems expect. Guardrail: Provide an explicit allowlist of optional fields and a naming pattern for dynamic keys. Validate output against a full schema, not just required fields.

02

Loss of Nested Context During Flattening

What to watch: When stripping extra fields from nested objects, the prompt flattens or drops parent context, breaking relational integrity. Guardrail: Require the prompt to preserve the original nesting structure and only remove leaf-level fields not in the schema. Log the full path of every removed field.

03

Over-Aggressive Enum Stripping

What to watch: The model removes legitimate enum values that are valid but rare, treating them as hallucinations because they don't appear in a limited example set. Guardrail: Supply the complete enum definition in the prompt. Add a pre-removal check: if a value matches the enum's semantic category, keep it even if the exact string isn't in the examples.

04

Silent Removal Without Audit Trail

What to watch: The prompt strips fields successfully but provides no log of what was removed, making it impossible to debug downstream data gaps. Guardrail: Require the output to include a removed_fields array with field paths, values, and removal reasons. Pipe this to observability, not just the response body.

05

Source-Grounded Field Misclassification

What to watch: A field is present in the source document but absent from the target schema, so the prompt removes it—yet the field contains critical context needed for human review. Guardrail: Add a preserve_for_review list for fields that should survive even if they don't map to the schema. Route these to a human review queue instead of stripping them.

06

Schema Drift After Prompt Freeze

What to watch: The target schema evolves, but the prompt's field allowlist is hardcoded. New legitimate fields are stripped as hallucinations. Guardrail: Load the schema dynamically at runtime rather than embedding it statically in the prompt. Version the schema and log which version was used for each removal decision.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to test the Extra Hallucinated Field Removal Prompt Template before shipping. Each criterion targets a specific failure mode observed in production when models strip or preserve fields incorrectly.

CriterionPass StandardFailure SignalTest Method

Hallucinated Field Removal

All fields not in [ALLOWED_SCHEMA] are removed from output

Output contains a key not present in the allowed schema list

Diff output keys against [ALLOWED_SCHEMA]; count unexpected keys

Legitimate Field Preservation

All fields listed in [ALLOWED_SCHEMA] are present in output with original values unchanged

A field from [ALLOWED_SCHEMA] is missing or its value was altered

Assert output key set equals [ALLOWED_SCHEMA] key set; assert value equality for each key

Removal Audit Log Completeness

Every removed field appears in [REMOVAL_LOG] with field name, value summary, and removal reason

A removed field is absent from [REMOVAL_LOG] or reason is empty

Parse [REMOVAL_LOG]; verify count matches removed fields; check reason field is non-empty for each entry

Nested Field Handling

Hallucinated nested keys inside allowed parent objects are removed; allowed nested keys are preserved

A hallucinated nested key survives or an allowed nested key is stripped

Flatten output and allowed schema; compare leaf-level key sets

Null Value Preservation

Fields in [ALLOWED_SCHEMA] with null values are preserved as null, not removed

A null-valued allowed field is missing from output

Assert key exists in output; assert value is null

Empty Object and Array Handling

Empty objects or arrays in allowed fields are preserved; empty objects in hallucinated fields are removed

An empty allowed container is removed or an empty hallucinated container survives

Check presence of empty containers against [ALLOWED_SCHEMA] membership

Removal Log Format Validity

[REMOVAL_LOG] is valid parseable JSON matching the specified log schema

[REMOVAL_LOG] is malformed JSON or missing required log fields

Parse [REMOVAL_LOG] as JSON; validate against log schema with field_name, value_preview, reason

No Silent Data Loss

Output contains exactly the allowed fields with original values; no fields are silently dropped without logging

An allowed field is absent from both output and [REMOVAL_LOG]

Cross-reference output keys and removal log keys against [ALLOWED_SCHEMA]; flag any allowed field missing from both

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a simple schema list and a single allowed_fields array. Skip the removal audit log and rely on manual spot-checking of outputs. Accept string-based field matching without fuzzy or semantic comparison.

code
Remove any fields not in [ALLOWED_FIELDS]. Return only the cleaned object.

Watch for

  • Legitimate fields removed because of naming variations (e.g., customer_id vs customerId)
  • No visibility into what was removed or why
  • Silent failures when the schema list is incomplete
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.