This playbook is for data ingestion engineers who need to clean and deduplicate model-generated records in a single repair pass. The prompt normalizes variant forms of values (dates, names, identifiers) according to configurable rules, then deduplicates records that become identical after canonicalization. Use this when a model outputs a list of entities, products, or contacts with inconsistent formatting and potential duplicates. The core job-to-be-done is taking a batch of records that are semantically equivalent but syntactically varied and collapsing them into a clean, canonical set without losing unique records.
Prompt
Canonicalization and Deduplication Combo Prompt

When to Use This Prompt
A practical guide for data ingestion engineers who need to clean and deduplicate model-generated records in a single repair pass.
Do not use this for semantic deduplication where records are similar but not identical after normalization. For example, if two contact records have different email addresses but likely refer to the same person, this prompt will not merge them—use the Fuzzy Deduplication with Confidence Threshold Prompt instead. This prompt assumes you have a defined set of canonicalization rules (e.g., lowercase emails, ISO 8601 dates, trimmed whitespace) and that records which normalize to the same string representation are true duplicates. It also assumes the input is a batch of records, not a streaming pipeline; for streaming, see the Duplicate Sentence Stripping Prompt Template with its streaming-compatible variant.
Before wiring this into production, ensure you have a pre/post cardinality comparison harness in place. The prompt should return both the deduplicated record set and a count of removed duplicates so you can validate that the reduction is reasonable. If the deduplication rate exceeds expected thresholds, flag the batch for human review—aggressive normalization rules can collapse records that should remain distinct. Pair this prompt with the Output Deduplication Audit Trail Prompt if you need traceable decisions for governance or compliance workflows.
Use Case Fit
Where the canonicalization-and-deduplication combo prompt works and where it introduces risk. This prompt is designed for data ingestion pipelines that need both value normalization and deduplication in a single repair pass.
Good Fit: Post-Ingestion Cleanup
Use when: You have a batch of records already extracted by a model and need to normalize variant values (e.g., 'USA' vs 'United States') before deduplicating. Guardrail: Run canonicalization rules first, then deduplicate. Always compare pre- and post-cardinality to detect over-merging.
Bad Fit: Real-Time Streaming
Avoid when: You need sub-second deduplication on a per-record basis in a streaming pipeline. The combo prompt is too heavy for hot paths. Guardrail: Use a deterministic hash-based deduplication in the application layer for real-time use. Reserve this prompt for batch repair jobs.
Required Input: Canonicalization Rules
Risk: Without explicit canonicalization rules, the model invents its own normalization, leading to inconsistent merges. Guardrail: Always provide a structured ruleset mapping variant forms to canonical values. Test the ruleset against a labeled sample before production use.
Required Input: Identity Key Configuration
Risk: The model deduplicates on the wrong fields if identity keys are not specified, collapsing records that should remain distinct. Guardrail: Explicitly declare which fields constitute a unique record. Validate that no two distinct source records share the same identity key values.
Operational Risk: Silent Data Loss
Risk: Deduplication removes records without an audit trail, making it impossible to verify correctness or recover lost data. Guardrail: Always output a deduplication manifest mapping removed record IDs to the surviving canonical record. Log pre- and post-counts as a metric.
Operational Risk: Canonicalization Drift
Risk: Canonicalization rules that worked last month fail on new variant forms, causing duplicates to survive the process. Guardrail: Monitor the deduplication rate over time. A sudden drop signals rule drift. Schedule periodic review of unmerged near-duplicates to update the ruleset.
Copy-Ready Prompt Template
A copy-ready prompt that normalizes variant values and deduplicates records in a single pass, with placeholders for your data, rules, and output schema.
This prompt performs canonicalization and deduplication as a combined repair operation. It first normalizes specified fields to a canonical form using your rules, then removes records that become identical after normalization. Use it when you need to clean ingested data where the same entity appears under different surface forms—such as inconsistent company names, address variants, or product identifiers—and you want one deduplicated, normalized result set without running two separate pipelines.
textYou are a data repair system. Your task is to canonicalize and deduplicate records in a single pass. ## INPUT [INPUT] ## CANONICALIZATION RULES Apply these normalization rules to each record before deduplication: [CANONICALIZATION_RULES] ## DEDUPLICATION KEY After canonicalization, two records are duplicates if they match on these fields: [DEDUPLICATION_KEY_FIELDS] ## CONFLICT RESOLUTION When duplicates are found, keep the record that satisfies this rule: [CONFLICT_RESOLUTION_RULE] ## OUTPUT SCHEMA Return a JSON object with this exact structure: { "canonicalized_records": [ // Array of deduplicated records after canonicalization, matching [OUTPUT_SCHEMA] ], "removed_duplicates": [ { "removed_record": { /* the record that was removed */ }, "kept_record_index": 0, "match_reason": "string explaining why these were duplicates" } ], "statistics": { "input_record_count": 0, "output_record_count": 0, "duplicates_removed": 0, "canonicalization_changes": 0 } } ## CONSTRAINTS [CONSTRAINTS] ## EXAMPLES [EXAMPLES] ## RISK LEVEL [RISK_LEVEL] Before returning, verify: 1. Every output record matches the canonicalization rules. 2. No two output records match on all deduplication key fields. 3. The statistics block is accurate. 4. Every removed duplicate has a clear match reason.
Adaptation guidance: Replace [INPUT] with your raw records in JSON array format. Populate [CANONICALIZATION_RULES] with field-by-field normalization instructions—for example, lowercase email addresses, strip whitespace from names, map department codes to a standard taxonomy, or normalize date formats to ISO 8601. Set [DEDUPLICATION_KEY_FIELDS] to the field combination that defines identity after normalization, such as ["normalized_email", "normalized_phone"]. Choose a [CONFLICT_RESOLUTION_RULE] like keep the record with the most recent timestamp or keep the record with the most populated fields. Add [CONSTRAINTS] for domain-specific rules such as do not merge records with different account IDs or flag but do not remove records where confidence is below 0.8. Include [EXAMPLES] showing a before/after pair with at least one normalization change and one deduplication. Set [RISK_LEVEL] to low, medium, or high to control downstream behavior—high-risk workflows should route removed duplicates to a human review queue rather than discarding them silently.
Wire this prompt into a repair pipeline that runs after initial extraction or generation. Validate the output JSON against the schema before accepting it. Compare statistics.input_record_count against your actual input count to detect truncation. For high-risk data, log every removed_duplicates entry to an audit table and require human approval before the deduplicated set replaces source-of-truth records. Avoid using this prompt when records have semantic identity that cannot be captured by field-level canonicalization rules alone—those cases need an LLM judge deduplication rubric instead.
Prompt Variables
Required and optional inputs for the canonicalization and deduplication combo prompt. Validate each input before calling the model to prevent repair-loop failures.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[INPUT_RECORDS] | The raw list, array, or newline-delimited set of records to canonicalize and deduplicate | ["John Smith", "smith, john", "J. Smith"] | Must be a non-empty string or valid JSON array. Reject if null or empty. Max 5000 records per call. |
[CANONICALIZATION_RULES] | Ordered list of normalization rules to apply to each record before comparison | ["lowercase", "strip_punctuation", "sort_words", "expand_abbreviations:abbrev_map.json"] | Must be a valid JSON array of rule names. Each rule must exist in the system's rule registry. Reject unknown rules. |
[MATCH_THRESHOLD] | Confidence threshold for declaring two canonicalized records as duplicates | 0.85 | Must be a float between 0.0 and 1.0. Values below 0.7 increase false positives; values above 0.95 risk missed duplicates. Default 0.85 if omitted. |
[OUTPUT_SCHEMA] | Expected structure for the deduplicated output | {"canonical_records": [], "duplicate_map": {}, "pre_count": 0, "post_count": 0} | Must be a valid JSON Schema or example object. The prompt will return records matching this shape. Validate output against this schema post-generation. |
[PRIORITY_RULE] | Rule for selecting the canonical representative when duplicates are found | keep_longest | Must be one of: keep_longest, keep_shortest, keep_first, keep_most_complete, keep_highest_confidence. Required if multiple records canonicalize to the same form. |
[ABBREVIATION_MAP] | Optional dictionary for expanding abbreviations during canonicalization | {"st": "street", "ave": "avenue", "corp": "corporation"} | If provided, must be a valid JSON object. Keys and values must be strings. Null allowed if no abbreviation expansion is needed. |
[STOP_WORDS] | Optional list of words to ignore during canonicalization comparison | ["the", "a", "an", "and", "of"] | If provided, must be a valid JSON array of strings. Null allowed. Overly aggressive stop-word lists can cause false duplicate matches. |
Implementation Harness Notes
How to wire the canonicalization and deduplication combo prompt into a production data pipeline with validation, retries, and cardinality tracking.
This prompt is designed to operate as a single-pass repair step inside a data ingestion or batch processing pipeline. It expects a list of input records and a set of canonicalization rules, and it returns a deduplicated list where variant forms have been normalized before comparison. The harness must enforce that the output cardinality is less than or equal to the input cardinality, and that no record was dropped unless it became identical to another record after canonicalization.
Wire the prompt into your pipeline as a post-extraction, pre-load transform. The typical flow is: raw source → extraction prompt → schema validation → canonicalization + dedup prompt → final schema validation → load. Pass [INPUT_RECORDS] as a JSON array of objects, [CANONICALIZATION_RULES] as a map of field-to-rule entries (e.g., {"email": "lowercase_trim", "phone": "e164_format"}), and [OUTPUT_SCHEMA] as the expected record shape. The model should return a JSON object with canonicalized_records, removed_duplicates, and cardinality_report keys. Validate the response immediately: confirm len(canonicalized_records) + len(removed_duplicates) == len(input_records), and that every removed duplicate has a canonical_match_id pointing to a surviving record.
For production resilience, implement a retry wrapper around the prompt call. If the output fails structural validation (missing keys, wrong types, cardinality mismatch), retry up to two times with the validation error message appended to the prompt as [PREVIOUS_ERROR]. If retries are exhausted, route the batch to a human review queue with the input, the failed outputs, and the validation errors logged. Use a deterministic canonicalization library (e.g., a phone number parser or email normalizer) to pre-process fields where possible before the prompt runs—this reduces model variance and token cost. Log the cardinality_report for every batch to track deduplication rates over time and detect drift in input data quality. Avoid using this prompt for real-time, single-record flows; it is optimized for batch sizes between 10 and 200 records where cross-record comparison is valuable.
Expected Output Contract
Fields, format, and validation rules for the canonicalization-and-deduplication combo prompt response. Use this contract to parse, validate, and integrate the model output into downstream pipelines.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
canonicalized_records | Array of objects | Must be a JSON array. Each element must conform to the [OUTPUT_SCHEMA] defined in the prompt. Array length must be less than or equal to the input record count. | |
canonicalized_records[].record_id | String | Must be a non-empty string. Must be unique within the canonicalized_records array. Should correspond to a canonical identifier derived from the normalization rules. | |
canonicalized_records[].source_ids | Array of strings | Must contain at least one element. Each element must match an original record ID from [INPUT_RECORDS]. No duplicate source_ids across different canonicalized_records entries. | |
canonicalized_records[].canonical_values | Object | Must conform to the field structure defined in [CANONICALIZATION_RULES]. All required fields from the rules must be present. Values must be in their normalized form. | |
deduplication_summary | Object | Must contain pre_count, post_count, and duplicate_groups fields. pre_count must equal the number of input records. post_count must equal the length of canonicalized_records. | |
deduplication_summary.pre_count | Integer | Must be a positive integer. Must match the count of records in [INPUT_RECORDS]. | |
deduplication_summary.post_count | Integer | Must be a positive integer less than or equal to pre_count. Must equal canonicalized_records.length. | |
deduplication_summary.duplicate_groups | Integer | Must be a non-negative integer. Must equal the count of canonicalized_records entries where source_ids.length > 1. |
Common Failure Modes
What breaks first when combining canonicalization and deduplication in one pass, and how to guard against it.
Canonicalization Collision
What to watch: Different source values normalize to the same canonical form, causing false-positive merges. For example, 'St. Louis' and 'Saint Louis' become identical, but might refer to different entities in different contexts. Guardrail: Include a pre-merge diff log that records which original values collapsed together, and require human review when collision count exceeds a configurable threshold.
Lossy Normalization Before Comparison
What to watch: Aggressive canonicalization strips distinguishing information before deduplication runs, making records appear identical when they aren't. Phone numbers normalized to digits-only lose extension info; names lowercased lose capitalization signals. Guardrail: Run deduplication on both canonicalized and original forms, flagging records that match only after normalization for secondary review.
Order-Dependent Merge Instability
What to watch: When canonicalization rules are applied in a fixed sequence, the output changes depending on input order. Record A processed before Record B may produce a different canonical form than B before A. Guardrail: Implement a two-pass approach: first pass canonicalizes all records independently, second pass deduplicates the stable canonical set. Validate with shuffled input order tests.
Silent Cardinality Mismatch
What to watch: The prompt returns deduplicated output without reporting how many records were removed, making it impossible to detect over-aggressive deduplication or canonicalization bugs in production. Guardrail: Require the output to include pre-count, post-count, and removed-count fields. Set up monitoring alerts when deduplication ratio exceeds historical baseline by more than 2 standard deviations.
Canonicalization Rule Drift
What to watch: Rules defined in the prompt (e.g., 'normalize state abbreviations to full names') are applied inconsistently by the model across long batches, especially near context window limits. Guardrail: Extract and validate a sample of canonicalized values against a reference implementation in application code. If model output diverges from deterministic canonicalization, route to post-processing instead of trusting the prompt.
Ambiguous Merge Conflict Resolution
What to watch: When two canonicalized records match but have conflicting non-key fields, the model silently picks one value or hallucinates a blend. Guardrail: Define explicit conflict resolution rules in the prompt (keep-longest, keep-most-recent, keep-from-first-occurrence). Include a conflicts array in the output schema listing every field where values diverged and which rule resolved it.
Evaluation Rubric
Criteria for testing the Canonicalization and Deduplication Combo Prompt before production deployment. Each row defines a pass standard, a failure signal, and a concrete test method.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Canonicalization rule application | All values in [CANONICALIZATION_RULES] are applied correctly to the input; variant forms are normalized to the specified canonical form. | Output contains a value that should have been normalized but remains in its original variant form. | Run a golden test set of 20 known variant-canonical pairs through the prompt. Assert 100% match between output and expected canonical forms. |
Post-canonicalization deduplication | Records that become identical after canonicalization are reduced to a single record. Cardinality reduction matches manual count. | Duplicate records remain in the output after canonicalization. Pre/post cardinality comparison shows no reduction when duplicates are known to exist. | Provide a batch where 5 records collapse to 2 after canonicalization. Assert output array length equals 2 and both records are present. |
Pre/post cardinality comparison accuracy | The [PRE_COUNT] and [POST_COUNT] fields in the output match the actual input record count and output record count. | Reported counts are off by one or more. Mismatch between reported [POST_COUNT] and actual length of the output array. | Parse the output JSON. Assert output.metadata.pre_count equals the number of input records. Assert output.metadata.post_count equals the length of output.records. |
Non-duplicate record preservation | Records that do not become duplicates after canonicalization are all present in the output, with no data loss. | A legitimate unique record is missing from the output. Field values on a unique record are altered unexpectedly. | For a batch with 3 unique records and 2 that collapse, assert output.records contains exactly 4 entries. Diff each unique record against its input. |
Conflict resolution for mismatched fields | When two records canonicalize to the same key but have conflicting non-key fields, the [CONFLICT_RESOLUTION] rule is applied correctly. | Conflicting fields are merged arbitrarily, dropped silently, or cause the prompt to error instead of applying the configured rule. | Provide two records with same canonical key but different 'status' fields. With rule 'keep_longest', assert the longer status value survives. |
Empty input handling | An empty input array produces a valid output with [PRE_COUNT] of 0, [POST_COUNT] of 0, and an empty records array. | Prompt returns an error, a null value, or a malformed response when given an empty input. | Send input with records: []. Assert output is valid JSON with records: [], pre_count: 0, post_count: 0. |
Output schema compliance | The output strictly matches the [OUTPUT_SCHEMA] definition. All required fields are present and correctly typed. | A required field is missing, a field has the wrong type, or an extra hallucinated field appears. | Validate the full output against the JSON Schema provided in [OUTPUT_SCHEMA] using a standard schema validator. Assert no validation errors. |
Single-record input passthrough | An input with a single record returns that record unchanged, with [PRE_COUNT] of 1 and [POST_COUNT] of 1. | The single record is dropped, duplicated, or altered when no canonicalization or deduplication should occur. | Send a batch with one record that has no variants. Assert output.records contains exactly that record with identical field values. |
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 sample of 20-50 records. Use a single canonicalization rule (e.g., lowercase + trim) and exact-match deduplication. Skip the cardinality comparison harness and manually inspect output.
codeCanonicalize [FIELD] using [RULE]. Remove exact duplicates after canonicalization.
Watch for
- Over-normalization collapsing distinct records (e.g., "St. John" and "Saint John")
- No pre/post count validation, so silent data loss is possible
- Canonicalization rules that work on samples but fail on full production data

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