This prompt is designed for RAG pipeline builders who observe redundant retrieval across conversation turns. The core job-to-be-done is filtering the current turn's retrieved passages to remove any evidence that has already been cited in prior answers, producing a deduplicated evidence set. The ideal user is an AI engineer or backend developer who controls the retrieval-to-generation handoff and has access to both the conversation history and the current retrieval results. Required context includes: the full conversation history with explicit source citations in prior assistant messages, the current user query, and the raw list of retrieved passages for the current turn. Without citation tracking in your history, this prompt cannot function because it relies on comparing new passage identifiers or content against previously cited sources.
Prompt
Conversation History Deduplication Prompt for RAG

When to Use This Prompt
Identify the specific conditions and system requirements for deploying the conversation history deduplication prompt in a multi-turn RAG pipeline.
Deploy this prompt when your RAG system exhibits answer repetition across turns, when context windows are tight and you need to maximize novel information density, or when you need to guarantee that each turn's answer adds incremental value beyond what was already stated. The prompt acts as a filter between retrieval and generation—it should be inserted after retrieval but before the generator prompt assembles its final context. For implementation, you will need to pass the conversation history as a structured list of prior assistant messages with their citation blocks, and the current turn's retrieved passages with unique identifiers (such as chunk IDs, document IDs, or content hashes). The prompt compares these and outputs only the passages that contain information not already covered by previously cited sources. You should validate the output by checking that no passage ID in the deduplicated set appears in the prior citations list, and that the total token count of the deduplicated set is less than or equal to the original retrieval set.
Do not use this prompt for single-turn Q&A systems where there is no conversation history to deduplicate against. Do not use it when your RAG pipeline lacks citation tracking or when prior answers do not contain explicit source references. Avoid this prompt when the conversation history is extremely long and the cost of processing all prior citations exceeds the benefit of deduplication—in those cases, consider a session summarization prompt first. Also avoid this prompt when retrieved passages contain time-sensitive information where even identical sources may need re-citation due to temporal context changes. The next step after implementing this prompt is to wire it into your RAG pipeline's context assembly stage and add eval checks for novelty detection and information loss prevention, as described in the implementation harness section.
Use Case Fit
Where the conversation history deduplication prompt fits into a production RAG pipeline, and where it introduces risk or operational overhead.
Good Fit: High Redundancy Retrieval
Use when: Your retriever returns overlapping chunks across turns, causing the model to re-cite the same evidence. Guardrail: Apply deduplication before context assembly to reduce token waste and improve answer conciseness.
Bad Fit: Single-Turn or Stateless Q&A
Avoid when: The system has no conversation history or each turn is independent. Guardrail: Skip the deduplication step entirely; it adds latency with no benefit and may incorrectly filter evidence.
Required Input: Prior Answer Citations
Risk: The prompt cannot deduplicate without knowing what was already cited. Guardrail: Always pass the prior turn's answer with its source identifiers. A missing citation list causes the prompt to fail silently or filter nothing.
Operational Risk: Information Loss
Risk: Aggressive deduplication may remove a passage that is partially novel or newly relevant in the current turn. Guardrail: Implement a semantic overlap threshold and log all removed passages for audit. Never hard-delete without a recovery path.
Operational Risk: Citation Drift
Risk: Deduplication can break citation chains if source IDs change between retrieval calls. Guardrail: Normalize source identifiers before comparison. Use content hashing as a fallback when IDs are unreliable.
Good Fit: Long Multi-Turn Sessions
Use when: Conversations extend beyond 5+ turns and the context window is under pressure. Guardrail: Combine deduplication with session summarization to maximize evidence freshness within token budgets.
Copy-Ready Prompt Template
A reusable prompt template for deduplicating retrieved evidence across conversation turns, ensuring new answers only cite novel passages.
This prompt template sits between your retrieval step and answer generation in a multi-turn RAG pipeline. Its job is to compare a freshly retrieved set of evidence chunks against the evidence already cited in previous conversation turns, then output a deduplicated set containing only novel passages. Use this when your retriever returns overlapping or identical chunks across turns, causing repetitive answers that waste context budget and erode user trust.
textYou are a retrieval deduplication filter for a multi-turn RAG system. Your task is to compare a set of newly retrieved evidence passages against passages already cited in prior conversation turns. Output only the novel passages that contain information not already covered by the previously cited evidence. [CONVERSATION_HISTORY] [RETRIEVED_EVIDENCE] [OUTPUT_SCHEMA] [CONSTRAINTS] [EXAMPLES]
Adapt this template by populating the placeholders with your specific pipeline data. [CONVERSATION_HISTORY] should contain the prior turns with their cited source IDs and key claims. [RETRIEVED_EVIDENCE] should be the raw retrieval results for the current turn, each with a unique passage ID. [OUTPUT_SCHEMA] must define the exact JSON structure you expect, including fields for passage ID, content, and a novelty flag. [CONSTRAINTS] should specify your deduplication rules: whether near-duplicates count as duplicates, how to handle partial overlap, and whether to preserve or discard passages that add minor new details. [EXAMPLES] should include at least one case where a passage is kept and one where it is discarded, showing the reasoning. After pasting this into your pipeline, validate the output against your schema before passing it to the answer generation step. For high-stakes domains, add a human review gate when the deduplication rate exceeds 80%, as aggressive filtering may indicate information loss.
Prompt Variables
Inputs required for the Conversation History Deduplication Prompt. Validate each variable before calling the model to prevent redundant evidence from leaking into the context window.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[CURRENT_QUERY] | The user's latest question or instruction that requires evidence synthesis. | What are the side effects of the new firmware update? | Must be a non-empty string. Check for null or whitespace-only input before assembly. |
[RETRIEVED_EVIDENCE] | The full set of passages retrieved for the current turn, including metadata. | [{"id": "doc_42_p3", "text": "Firmware v2.1 resolves..."}] | Must be a valid JSON array of objects with 'id' and 'text' fields. Reject if empty array or parse failure. |
[PRIOR_CITATION_IDS] | A list of source identifiers already cited in the assistant's previous answers within the session. | ["doc_17_p1", "doc_42_p3", "doc_55_p8"] | Must be a valid JSON array of strings. An empty array is allowed for the first turn. Validate JSON parse. |
[PRIOR_ANSWER_SUMMARIES] | A condensed list of claims the assistant has already made, mapped to their source IDs. | [{"claim": "Update requires reboot", "source_id": "doc_42_p3"}] | Must be a valid JSON array of objects. Each object requires 'claim' and 'source_id' fields. Null allowed for first turn. |
[DEDUPLICATION_MODE] | Controls whether to remove exact duplicates only or also semantically redundant passages. | "semantic" | Must be one of the enum values: 'exact', 'semantic'. Default to 'semantic' if null. Reject unknown values. |
[MAX_OUTPUT_PASSAGES] | The maximum number of unique passages to return after deduplication. | 5 | Must be a positive integer. Validate type and range (1-20). If null, default to 5. Reject non-integer or out-of-range values. |
[SESSION_ID] | A unique identifier for the conversation session, used for logging and traceability. | "sess_9a8b7c" | Must be a non-empty string. Used for observability, not model behavior. Log a warning if missing but do not block execution. |
Implementation Harness Notes
How to wire the deduplication prompt into a RAG pipeline with validation, retry, and logging.
The deduplication prompt should sit between your retrieval step and your answer generation step, operating as a filter that reduces the evidence payload before it reaches the synthesis model. In a typical RAG pipeline, you retrieve chunks for each user turn, but many of those chunks will overlap with passages already cited in prior answers. Running this prompt before answer generation prevents the model from re-synthesizing stale evidence and keeps your context window focused on genuinely new information. The prompt expects a structured input containing the current query, the newly retrieved passages, and a summary of previously cited evidence from the conversation history. You should assemble this input programmatically from your session store and retrieval index rather than asking the user to provide it.
Wire the prompt into your pipeline as a synchronous pre-processing step with a strict output contract. The prompt returns a JSON object with a deduplicated_passages array and a removed_passages array, each containing passage IDs and a brief reason for inclusion or removal. Implement a JSON schema validator immediately after the model response to enforce this structure. If validation fails, retry once with the validation error message appended to the prompt as a correction hint. Log every deduplication decision—including which passages were removed and why—to your observability platform so you can audit for information loss. For high-stakes domains where removing a passage could drop critical evidence, add a secondary check: if the deduplication step removes more than 50% of retrieved passages, flag the turn for human review or re-retrieval with adjusted similarity thresholds before proceeding to answer generation.
Model choice matters here. This is a classification-and-filtering task that benefits from deterministic behavior, so prefer models with strong instruction-following and low temperature settings (0.0–0.2). Avoid models that tend to over-explain or add commentary outside the requested JSON schema. If you're using a model that doesn't reliably produce valid JSON, wrap the call in a retry loop with schema validation and consider using structured output APIs like function calling or constrained decoding to enforce the output shape. Do not let a deduplication failure silently pass through to the answer generation step—a failure here means your synthesis model will receive redundant context, which defeats the purpose of the prompt and wastes token budget on already-cited evidence. Build a circuit breaker: if deduplication fails after two retries, log the failure, pass the full retrieval set to answer generation with a warning flag, and alert the on-call channel so the pipeline degradation is visible.
Expected Output Contract
Schema, types, and validation rules for the deduplication output. Use this contract to build a post-processing validator that rejects malformed responses before they enter the RAG pipeline.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
deduplicated_passages | Array of objects | Must be a JSON array. Reject if not parseable as JSON or if array is missing. | |
deduplicated_passages[].passage_id | String | Must match the exact passage_id from the [INPUT_PASSAGES] array. Reject if ID is fabricated or missing. | |
deduplicated_passages[].passage_text | String | Must be a non-empty string. Reject if null, empty, or whitespace-only. Length must be >= 10 characters. | |
removed_passage_ids | Array of strings | Must be an array of passage_id strings that were removed. Each ID must exist in [INPUT_PASSAGES]. Reject if any ID is not found in input. | |
removal_reasons | Array of objects | Must be an array with the same length as removed_passage_ids. Each entry must map to the corresponding removed passage. | |
removal_reasons[].passage_id | String | Must match an ID in removed_passage_ids. Reject if IDs don't align 1:1. | |
removal_reasons[].reason | String enum | Must be one of: 'near_duplicate', 'subsumed_by_other_passage', 'already_cited_in_prior_turn'. Reject on unknown values. | |
removal_reasons[].reference_passage_id | String or null | If reason is 'near_duplicate' or 'subsumed_by_other_passage', must be a valid passage_id from deduplicated_passages. If 'already_cited_in_prior_turn', must be null. | |
prior_turn_citations_used | Array of strings | If present, each string must match a passage_id from [PRIOR_CITATION_IDS]. Reject if fabricated IDs are found. Null allowed if no prior citations exist. | |
information_loss_warning | Boolean | Must be true if any removed passage contains a unique fact, date, number, or named entity not present in the retained passage. Reject if false when unique information is clearly dropped. | |
deduplication_confidence | Number | Must be a float between 0.0 and 1.0. Reject if out of range. Values below 0.7 should trigger a human review flag in the harness. | |
processing_notes | String or null | If not null, must be a non-empty string summarizing edge cases or borderline decisions. Null allowed when deduplication is straightforward. |
Common Failure Modes
What breaks first when deduplicating conversation history evidence and how to guard against it.
Over-Deduplication of Novel Information
What to watch: The prompt removes passages that appear similar to prior evidence but contain new facts, timestamps, or qualifiers. Cosine similarity or surface-level overlap causes information loss. Guardrail: Require semantic difference detection, not just token overlap. Add a test set of near-duplicate passages with one changed fact and verify the changed passage survives deduplication.
Citation Chain Breakage
What to watch: Removing a passage because it was cited in a prior turn breaks the citation chain when the user asks a follow-up that requires re-examining that same evidence. The model loses access to the source. Guardrail: Distinguish between 'previously cited' and 'previously used.' Retain passages when the current question references or challenges a prior answer. Log dropped citations for audit.
History Window Contamination
What to watch: The deduplication prompt itself consumes significant context tokens, especially when prior answers and their citations are included as reference material. The guardrail becomes more expensive than the problem it solves. Guardrail: Pass only citation IDs and brief passage fingerprints into the dedup prompt, not full prior answers. Use application-layer caching for prior evidence hashes.
False Novelty from Paraphrased Evidence
What to watch: The same fact expressed in different wording across two retrieval calls is treated as new evidence. The model fails to recognize semantic equivalence and retains redundant passages. Guardrail: Include explicit instruction to compare claims, not phrasing. Add few-shot examples showing paraphrased duplicates that should be removed. Test with a passage rewritten at different reading levels.
Temporal Relevance Misjudgment
What to watch: A passage cited in turn one is correctly deduplicated in turn two, but turn three asks a question where that passage is now the most relevant evidence. The dedup decision from turn two persists and blocks retrieval. Guardrail: Deduplicate per-turn, not cumulatively across the entire session. Re-evaluate relevance for each new question. Never permanently exclude a source based on prior dedup decisions.
Silent Evidence Dropping Without Audit Trail
What to watch: The prompt removes passages but provides no record of what was dropped or why. When an answer is wrong or incomplete, operators cannot determine whether deduplication removed critical evidence. Guardrail: Require the prompt to output a structured dedup log: dropped passage IDs, reason codes (duplicate, irrelevant, stale), and the retained passage it maps to. Store this log alongside the answer for debugging.
Evaluation Rubric
Run these checks on a golden dataset of multi-turn conversations with known novel and redundant passages. Each criterion targets a specific failure mode in deduplication.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Novel Passage Retention | All passages containing information not present in prior turns are retained in the deduplicated set | A novel passage is missing from the output, causing information loss | Compare output passage IDs against a labeled golden set where novel passages are pre-identified |
Redundant Passage Removal | All passages whose content is fully covered by prior-turn citations are removed | A redundant passage appears in the output, wasting context budget | Check output passage IDs against a labeled golden set where redundant passages are pre-identified |
Partial Overlap Handling | Passages with partial overlap are retained with a note indicating which portions are novel | A partially overlapping passage is either fully removed or retained without novelty annotation | Inspect output for passages flagged with novelty markers; verify markers match labeled overlap spans |
Citation Continuity | Deduplicated passages reference prior-turn citation IDs when overlap is detected | Output omits reference to prior citations, breaking the audit trail across turns | Scan output for prior-turn citation ID references; confirm presence for all overlapping passages |
Information Loss Rate | Zero novel facts from the current retrieval set are absent from the deduplicated output | A fact present in retrieved passages but absent from prior turns is missing from output | Run fact-level comparison between input retrieval set and deduplicated output using automated fact extraction |
False Novelty Flagging | No passage is marked as novel when its content already appears in prior-turn citations | A passage is retained and labeled novel despite full coverage in prior answers | Cross-reference output novelty flags against prior-turn citation content using semantic similarity threshold |
Context Budget Efficiency | Deduplicated set uses at least 40% fewer tokens than the raw retrieval set when redundancy is present | Token count of deduplicated output equals or exceeds raw retrieval token count | Calculate token counts for raw retrieval set and deduplicated output; verify reduction ratio |
Multi-Turn Coherence Preservation | Answer quality using deduplicated context matches or exceeds answer quality using raw context on coherence metrics | Answers generated from deduplicated context show degraded coherence or missing supporting evidence | Generate answers from both raw and deduplicated context; compare using LLM judge on coherence and completeness |
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 small set of test conversation turns. Focus on getting the deduplication logic right before adding schema constraints. Run with a frontier model and manually inspect outputs.
code[SYSTEM] You are a conversation history deduplication assistant. Given the current retrieved passages and the prior conversation turns, remove any passages that were already cited or discussed in previous answers. Return only the novel passages. [PRIOR_CONVERSATION] [CONVERSATION_HISTORY] [RETRIEVED_PASSAGES] [PASSAGES] Return the deduplicated passages as a list.
Watch for
- Overly aggressive deduplication that removes complementary information
- Missing edge cases where the same fact appears with different wording
- 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