This prompt belongs in the pre-retrieval validation layer of a RAG pipeline. After a spelling corrector or grammar normalizer modifies a user query, this prompt compares the original and corrected versions to detect semantic drift. Its job is to answer one question: did the correction step preserve the user's intended meaning, or did it introduce a change that will send retrieval down the wrong path? Use it when your correction step could change technical terms, entity names, or domain-specific language—situations where a naive spell-checker might 'fix' a valid product code, a medical term, or a proper noun into something plausible but wrong.
Prompt
Query Intent Preservation During Correction Prompt Template

When to Use This Prompt
Defines the operational boundary for a semantic drift safety check that gates corrected queries before retrieval.
Do not use this prompt as the primary spelling corrector. It is a safety check, not a repair tool. It gates whether a corrected query proceeds to retrieval or is flagged for review. The ideal deployment point is immediately after any automated normalization step and before the query hits your vector store, keyword index, or hybrid retrieval layer. If the prompt returns a high drift score, the corrected query should be blocked, logged, and optionally routed to a human-in-the-loop review queue or a clarification prompt. If the drift score is low, the corrected query proceeds. This prompt is most valuable in domains where retrieval precision matters more than recall—healthcare, legal, finance, technical support, and any product where a wrong answer carries real cost.
Avoid deploying this prompt on every query in high-throughput, low-risk systems where the cost of an extra LLM call outweighs the benefit of drift detection. If your correction step is a simple regex or a deterministic dictionary lookup with no ambiguity, you likely don't need this gate. Also avoid using it when the correction step itself is an LLM—chaining two LLM calls for correction-then-validation creates latency and cost that may be better solved by a single, more carefully prompted correction step with built-in confidence scoring. For voice-to-text pipelines, pair this with a phonetic error correction prompt upstream; for multilingual systems, ensure the drift comparison accounts for translation-equivalent meaning rather than surface-form matching. Start by running this prompt on a sample of corrected queries and measuring the false-positive rate—queries flagged as drifted that humans would consider equivalent—before enabling it as a hard gate in production.
Use Case Fit
Where the Query Intent Preservation prompt works, where it fails, and what you must provide before putting it into a production RAG pipeline.
Good Fit: Post-Correction Safety Nets
Use when: a spelling, grammar, or normalization prompt has already produced a corrected query and you need a gate to verify that the correction did not change what the user meant. Guardrail: run this prompt after every automated correction step, not as a standalone fixer.
Bad Fit: Real-Time Chat Without Latency Budget
Avoid when: the system must return results in under 200ms and cannot afford an extra LLM call for intent comparison. Guardrail: use a fast embedding-distance threshold check as a pre-filter, and escalate to the full prompt only when the distance exceeds a calibrated boundary.
Required Input: Original and Corrected Query Pair
What to watch: running the prompt on only the corrected query without the original user input makes intent drift undetectable. Guardrail: always pass both [ORIGINAL_QUERY] and [CORRECTED_QUERY] as separate, immutable fields in the prompt template.
Required Input: Domain Glossary and Entity List
What to watch: the model may flag legitimate domain-term substitutions as semantic drift when it lacks context about your terminology. Guardrail: supply a [DOMAIN_GLOSSARY] of known synonyms, acronyms, and entity mappings so the model can distinguish valid normalization from meaning changes.
Operational Risk: Embedding Model Mismatch
What to watch: the semantic drift score produced by the prompt may use a different embedding model than your production retrieval pipeline, causing inconsistent gating decisions. Guardrail: calibrate the prompt's drift score against your production embedding model using a held-out set of human-annotated intent pairs before deployment.
Operational Risk: Over-Blocking Valid Corrections
What to watch: a conservative drift threshold can reject legitimate corrections, leaving noisy queries that still produce poor retrieval results. Guardrail: log every blocked correction with the drift score and original/corrected pair, then periodically review a sample to tune the acceptance threshold and identify systematic over-blocking patterns.
Copy-Ready Prompt Template
A copy-ready prompt template for verifying that spelling or grammar corrections preserve the user's original intent, producing a before-and-after comparison with a semantic drift score.
This prompt template is designed to be pasted directly into your orchestration layer. It takes an original user query and its corrected version, then verifies whether the correction preserved the original intent. The model produces a structured comparison with a semantic drift score, a judgment on intent preservation, and a detailed rationale. This is a critical safety check in production RAG pipelines where automated correction can silently alter meaning.
textYou are a query intent preservation auditor for a production retrieval system. Your task is to compare an original user query with its corrected version and determine whether the correction preserved the original semantic intent. # INPUTS - Original Query: [ORIGINAL_QUERY] - Corrected Query: [CORRECTED_QUERY] - Correction Type: [CORRECTION_TYPE] // e.g., spelling, grammar, acronym expansion, punctuation normalization - Domain Context (optional): [DOMAIN_CONTEXT] // e.g., medical, legal, technical support, e-commerce # OUTPUT SCHEMA Return a valid JSON object with exactly these fields: { "intent_preserved": boolean, // true if the core meaning is unchanged "semantic_drift_score": number, // 0.0 to 1.0, where 0.0 = identical intent, 1.0 = completely different intent "drift_category": string, // one of: "none", "negligible", "minor", "moderate", "severe" "key_differences": [string], // list of specific semantic changes detected, empty array if none "rationale": string, // concise explanation of the judgment "recommendation": string // one of: "use_corrected", "use_original", "flag_for_review", "request_clarification" } # CONSTRAINTS 1. Focus on semantic meaning, not surface form. A rephrasing that preserves intent is acceptable. 2. Flag any change to entities, numbers, dates, negations, comparatives, or domain-specific terminology. 3. If the correction introduces ambiguity that was not present in the original, treat this as drift. 4. If the original query was ambiguous and the correction resolves it in one direction, note this as intent refinement, not preservation failure, but flag it for review. 5. For [RISK_LEVEL] = "high" (e.g., clinical, legal, financial queries), default to "flag_for_review" for any non-zero drift score. # EXAMPLES Example 1: Original: "wat is the does of aspirn for hart atack" Corrected: "what is the dose of aspirin for heart attack" Correction Type: spelling Output: {"intent_preserved": true, "semantic_drift_score": 0.0, "drift_category": "none", "key_differences": [], "rationale": "All corrections are surface-level spelling fixes. No semantic change detected.", "recommendation": "use_corrected"} Example 2: Original: "latest iPhone battery issues" Corrected: "latest iPhone battery life issues" Correction Type: grammar Output: {"intent_preserved": false, "semantic_drift_score": 0.6, "drift_category": "moderate", "key_differences": ["Added 'life' narrows query from general battery problems to battery longevity specifically"], "rationale": "The original query was broad about battery issues. The correction added 'life', which changes the scope to battery duration only.", "recommendation": "flag_for_review"} Now evaluate the provided query pair.
To adapt this template, replace the square-bracket placeholders at runtime. [ORIGINAL_QUERY] and [CORRECTED_QUERY] are mandatory. [CORRECTION_TYPE] should be populated from your correction pipeline's metadata so the model understands what transformation was applied. [DOMAIN_CONTEXT] is optional but strongly recommended for high-stakes domains where terminology sensitivity matters. [RISK_LEVEL] should be set by your application logic based on the query's downstream impact—use "high" for clinical, legal, financial, or safety-critical queries, and "standard" otherwise. Before deploying, run this prompt against a golden dataset of 50–100 annotated intent-preservation pairs to calibrate the drift score thresholds for your domain.
Prompt Variables
Required and optional inputs for the Query Intent Preservation prompt. Each variable must be populated before the prompt is sent to the model. Validation notes describe how to programmatically verify the input before execution.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[ORIGINAL_QUERY] | The raw user query before any correction was applied | show me the revenu for Q2 in APAC | Must be a non-empty string. Reject null or whitespace-only input. Log original for audit trail. |
[CORRECTED_QUERY] | The query after spelling, grammar, or normalization corrections | Show me the revenue for Q2 in APAC. | Must be a non-empty string. Compare to [ORIGINAL_QUERY] to confirm a transformation occurred. If identical, skip intent check. |
[CORRECTION_DIFF] | A machine-readable list of specific changes made between original and corrected | revenue: 'revenu' -> 'revenue'; casing: 'show' -> 'Show' | Must be a valid JSON array of change objects with 'field', 'from', and 'to' keys. Reject if diff is empty or unparseable. |
[DOMAIN_CONTEXT] | Optional domain glossary or taxonomy to ground intent interpretation | APAC: Asia-Pacific region; Q2: April 1 - June 30 fiscal period | If provided, must be a valid JSON object mapping terms to definitions. Null allowed. If null, model relies on general knowledge only. |
[EMBEDDING_MODEL] | Identifier for the embedding model used to compute semantic drift score | text-embedding-3-small | Must match a supported model name in your embedding service registry. Validate against allowed model list before calling embedding API. |
[DRIFT_THRESHOLD] | Maximum acceptable cosine distance between original and corrected query embeddings before flagging | 0.15 | Must be a float between 0.0 and 1.0. Values below 0.05 may cause false positives on trivial casing fixes. Default 0.15 if not specified. |
[OUTPUT_FORMAT] | Desired structure for the intent comparison output | json | Must be one of: 'json', 'text'. If 'json', validate output against [OUTPUT_SCHEMA] after generation. If 'text', human review required. |
Implementation Harness Notes
How to wire the intent preservation check into a production RAG pipeline with validation, retries, and human review gates.
The intent preservation prompt is not a standalone correction step; it is a guard that runs after a query correction module and before the corrected query is sent to retrieval. In a production RAG pipeline, the typical call order is: raw user query → spelling/grammar correction → intent preservation check → retrieval → generation. The prompt compares the original and corrected query strings, producing a semantic drift score and a judgment. This output must be consumed by application logic that decides whether to use the corrected query, fall back to the original, request human review, or ask the user for clarification.
Wire the prompt into your application as a synchronous pre-retrieval hook. After the correction module returns a corrected_query, call the intent preservation prompt with [ORIGINAL_QUERY] and [CORRECTED_QUERY] as inputs. Parse the JSON response to extract semantic_drift_score (a float from 0.0 to 1.0) and intent_preserved (a boolean). Implement a threshold gate: if intent_preserved is false or semantic_drift_score exceeds your configured threshold (start with 0.3 and tune against eval data), route to a fallback path. The fallback should use the original uncorrected query for retrieval and log the correction as rejected. For high-stakes domains such as clinical or legal search, add a human review queue when the drift score falls in an ambiguous band (e.g., 0.2–0.5). Log every comparison with original_query, corrected_query, drift_score, intent_preserved, rationale, and the final query_used for audit and eval improvement.
Model choice matters here. This prompt requires strong semantic comparison ability, not just pattern matching. Use a capable instruction-following model such as gpt-4o, claude-3-5-sonnet, or an equivalent. Avoid using a tiny or local model for this gate unless you have calibrated its drift scores against a human-annotated dataset. Validation: after parsing the JSON response, confirm that semantic_drift_score is a number between 0 and 1 and that intent_preserved is a boolean. If the model returns malformed JSON, retry once with a stricter schema instruction; if it fails again, fail closed by using the original query and logging the error. Eval integration: maintain a golden dataset of original-corrected query pairs with human-labeled intent preservation judgments. Run this prompt against that dataset weekly, tracking the F1 score of the intent_preserved flag and the mean absolute error of the drift score. Set a monitoring alert if the agreement rate with human labels drops below 90%. What to avoid: do not use this prompt as the correction step itself—it is a verification gate, not a rewriter. Do not skip the threshold gate and blindly trust the corrected query; even high-confidence corrections can invert meaning on domain-specific terms. Do not log raw queries containing PII without redaction; if your system handles personal data, run a PII redaction step before logging the comparison payload.
Expected Output Contract
Define the exact shape of the output from the Query Intent Preservation prompt. Use this contract to build a parser and validator in your application code before the output is passed to downstream retrieval or logging systems.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
original_query | string | Must exactly match the [UNCORRECTED_QUERY] input string. Fail if any character differs. | |
corrected_query | string | Must be a non-empty string. Fail if identical to original_query when a correction was expected, unless no corrections were needed. | |
intent_preserved | boolean | Must be true or false. Fail if null or missing. If false, the correction should be blocked or flagged for human review. | |
semantic_drift_score | float | Must be a number between 0.0 and 1.0. Fail if outside this range. A score > [DRIFT_THRESHOLD] should trigger intent_preserved: false. | |
corrections_applied | array of objects | Each object must contain 'type' (string), 'original' (string), and 'corrected' (string). Fail if the array is empty when corrected_query differs from original_query. | |
drift_rationale | string | Must be a non-empty string if semantic_drift_score > 0.0. Fail if missing when drift is detected. Should cite specific changed terms. | |
requires_human_review | boolean | Must be true if intent_preserved is false or semantic_drift_score > [DRIFT_THRESHOLD]. Fail if false when drift conditions are met. |
Common Failure Modes
What breaks first when preserving intent during query correction and how to guard against it.
Semantic Drift from Over-Correction
What to watch: The correction prompt fixes spelling or grammar but changes the underlying meaning. A typo like 'serverless' corrected to 'server less' inverts the technical intent. Guardrail: Run an embedding distance check between the original and corrected query. Set a maximum cosine distance threshold (e.g., 0.15) and flag corrections that exceed it for human review.
Domain Jargon Treated as Errors
What to watch: Technical terms, product names, or internal acronyms are 'corrected' to common dictionary words. 'k8s' becomes 'kids', 'GCP' becomes 'gap'. Guardrail: Supply a domain glossary as a protected term list in the prompt. Instruct the model to preserve any term matching the glossary exactly, and log every override for audit.
Intent Collapse in Ambiguous Queries
What to watch: A query with multiple valid interpretations gets resolved to a single, possibly wrong, meaning without surfacing the ambiguity. 'Java update' could mean the programming language or the island. Guardrail: Require the prompt to output an ambiguity flag and, when confidence is below a threshold, generate a clarification question instead of a single corrected query.
Loss of Entity Precision
What to watch: Named entities, version numbers, or identifiers are normalized into generic forms. 'Python 3.11 async bug' becomes 'Python async bug', losing the critical version constraint. Guardrail: Include an entity preservation instruction in the prompt that explicitly forbids modification of version strings, IDs, and capitalized multi-word entities. Validate with a regex diff post-correction.
Silent Failure on Non-English Input
What to watch: The correction model, trained predominantly on English, mangles queries in other languages by applying English spelling rules. A valid French or German query gets 'corrected' into nonsense. Guardrail: Add a language detection step before correction. Route non-English queries to language-specific correction prompts or flag them for human review if no language model is available.
Correction Chain Cascading Errors
What to watch: A query passes through multiple correction stages (spelling, then acronym expansion, then decomposition). An error introduced in stage one compounds through the pipeline. Guardrail: Log the input and output of every correction stage. Implement an end-to-end intent preservation eval that compares the final query against the original user input, not just the output of the last stage.
Evaluation Rubric
Criteria for testing whether the query correction prompt preserves the user's original intent. Use these checks before shipping to production.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Semantic Drift Threshold | Cosine similarity between original and corrected query embeddings is >= 0.95 | Similarity drops below 0.90 on held-out test pairs | Compute embedding distance on 100+ annotated query pairs; flag any pair below threshold for human review |
Entity Preservation | All named entities, product codes, and technical identifiers in [ORIGINAL_QUERY] appear unchanged in [CORRECTED_QUERY] | Entity is dropped, replaced with a synonym, or normalized to a different canonical form | Exact string match on extracted entity list; diff original vs corrected entity spans |
Negation Integrity | Negation words (not, never, don't, without) and their scope are preserved in the corrected query | Negation is removed or its scope shifts to a different clause | Parse dependency tree for negation markers; assert negation scope is identical before and after correction |
Temporal Constraint Stability | Date ranges, relative time expressions, and temporal modifiers in [ORIGINAL_QUERY] map to the same ISO 8601 interval after correction | Time expression is dropped, expanded, or narrowed beyond the original intent | Extract temporal expressions from both queries; compare resolved date ranges for equivalence |
Constraint Count Match | Number of explicit constraints (filters, conditions, exclusions) is identical between original and corrected query | Correction adds or removes a constraint not implied by the original query | Count constraint clauses in both queries; flag any delta > 0 for manual review |
Intent Classification Stability | Predicted intent label for [CORRECTED_QUERY] matches the label for [ORIGINAL_QUERY] | Intent classifier returns a different top-1 label after correction | Run both queries through the same intent classifier; assert label equality |
Human Agreement Rate |
| Human annotators flag > 5% of corrections as meaning-altering | Sample 50-100 corrections weekly; have two annotators rate intent preservation; measure inter-annotator agreement and pass rate |
Edge Case: Ambiguous Input | For queries with genuine ambiguity, the prompt returns a clarification flag rather than guessing a correction | Prompt confidently corrects an ambiguous query without signaling uncertainty | Curate 20 known-ambiguous queries; assert [CONFIDENCE_SCORE] < 0.7 or [NEEDS_CLARIFICATION] is true |
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
Use the base prompt with a simple before/after comparison. Drop the structured JSON output requirement and ask for a plain-text explanation of whether the correction changed the meaning. Accept a yes/no/maybe answer with a one-sentence rationale.
codeOriginal query: [ORIGINAL_QUERY] Corrected query: [CORRECTED_QUERY] Did the correction change the user's intended meaning? Answer YES, NO, or MAYBE with one sentence explaining why.
Watch for
- Overly cautious MAYBE responses on trivial punctuation fixes
- No numeric threshold to act on programmatically
- Model defaults to verbose explanations instead of actionable flags

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