GrepBoard/Manuals
605 manuals ·

Find near-duplicate names with different spellings using AI

·Tested on Claude Sonnet 5.5 · 2026-10·Test scope ↓·7 steps

Standardize irregular company names across spaces and legal suffixes using an AI mapping table, then verify distinct entities with a validation script.

When client ledgers contain inconsistent entries such as "Apex Logistics", "Apex Logistics", and "Apex Logistics Inc.", Excel's native Remove Duplicates treats each as a separate company. This fragments sales totals and corrupts account balances. Formulas like TRIM and SUBSTITUTE handle simple space trims, but struggle with inconsistent corporate suffixes (Inc., LLC, Corp.) and abbreviations scattered across thousands of rows.

Prompting an AI to merge names without strict boundaries introduces a different risk: collapsing distinct entities that happen to share word roots, such as "Nova Energy" and "Nova Capital". The reliable pattern is to generate a 1-to-1 mapping table from raw names to canonical names, verify entity separation with an automated script, and map clean names back to Excel via lookup formulas. Structural verification principles follow table format validation.

[1] Prepare the raw client list of 40 entries. This dataset contains 12 spelling and suffix variants, plus 2 pairs of distinct companies sharing common name prefixes (Nova Energy/Nova Capital, Beacon Medical/Beacon Robotics).

clients.en.txt
Apex LogisticsAlder Bio LabsSummit TechnologiesNova EnergyApex  LogisticsBirchwood Heavy IndustriesCrestview ConsultingBeacon MedicalCedar Coast ShippingVanguard SystemsPine Valley HealthDriftwood StudiosApex Logistics Inc.Summit TechElmwood PackagingNova CapitalCrestview Consulting GroupFoxglove SolutionsSummit Technologies Ltd.Granite State DynamicsVanguard  SystemsHarbor Light CapitalBeacon RoboticsIronclad SecurityApex Logistics, LLCJuniper Network WorksCrestview  ConsultingKeystone MaterialsBlue Horizon MediaLarkspur EngineeringFalcon GlobalMeadowbrook FoodsPine Valley Health LLCNorthstar AnalyticsOakridge MetalsBlue Horizon Media Corp.Redwood DentalFalcon Global Inc.Blue Horizon  MediaSilverline Aerospace

[2] Construct the prompt. Fix the output schema to a 3-column Markdown table (Raw Client Name, Canonical Name, Rationale), enforce separation of distinct legal entities, and provide examples using <example> tags.

text
You are a data cleaning and ERP client ledger specialist.Analyze the 40 client names provided in <clients> below and produce a mapping table that standardizes spelling variations (spacing differences, legal entity affixes, etc.). ## Rules1. Output only a Markdown table with exactly these 3 columns:   | Raw Client Name | Canonical Name | Rationale |2. Include all 40 items listed in <clients> without omitting any row.3. Group identical companies that differ only by leading/trailing spaces, internal whitespace, or legal entity markers (`Inc.`, `LLC`, `Corp.`, `Ltd.`, etc.) under a single Canonical Name. The canonical name should be the clean base company name without corporate entity markers.4. Critical constraint: Do NOT merge distinct legal entities that share partial words but represent different businesses (e.g., 'Nova Energy' vs 'Nova Capital', 'Beacon Medical' vs 'Beacon Robotics'). Keep them as separate canonical names.5. Do not include any introductory remarks, greetings, or explanations outside the table. <example>Input:Acme CorporationAcme  CorpAcme LogisticsAcme Medical Output:| Raw Client Name | Canonical Name | Rationale ||---|---|---|| Acme Corporation | Acme | Standardized legal marker || Acme  Corp | Acme | Normalized spacing and abbreviation || Acme Logistics | Acme Logistics | Distinct company name preserved (different sector) || Acme Medical | Acme Medical | Distinct company name preserved (similar prefix but different entity) |</example> <clients>{client_list}</clients>

[3] Execute the prompt in an isolated environment with --setting-sources "" to prevent configuration drift.

console
$ claude -p --model claude-sonnet-5-5 --max-turns 1 --tools "" --setting-sources "" --strict-mcp-config < run/en.1.prompt.txt > run/en.1.out.txt

Below is an excerpt from run/en.1.out.txt showing the generated mapping table.

output
| Raw Client Name | Canonical Name | Rationale ||---|---|---|| Apex Logistics | Apex Logistics | Already clean base name || Alder Bio Labs | Alder Bio Labs | Unique company, no variants || Summit Technologies | Summit Technologies | Already clean base name || Nova Energy | Nova Energy | Distinct company; not merged with Nova Capital || Apex  Logistics | Apex Logistics | Normalized internal spacing || Birchwood Heavy Industries | Birchwood Heavy Industries | Unique company, no variants || Crestview Consulting | Crestview Consulting | Already clean base name || Beacon Medical | Beacon Medical | Distinct company; not merged with Beacon Robotics |…| Apex Logistics Inc. | Apex Logistics | Removed legal marker "Inc." || Summit Tech | Summit Technologies | Abbreviation of "Technologies" standardized || Elmwood Packaging | Elmwood Packaging | Unique company, no variants || Nova Capital | Nova Capital | Distinct company; not merged with Nova Energy || Crestview Consulting Group | Crestview Consulting | Removed organizational suffix "Group" |…| Beacon Robotics | Beacon Robotics | Distinct company; not merged with Beacon Medical |…| Apex Logistics, LLC | Apex Logistics | Removed comma and legal marker "LLC" |…| Blue Horizon Media Corp. | Blue Horizon Media | Removed legal marker "Corp." || Redwood Dental | Redwood Dental | Unique company, no variants || Falcon Global Inc. | Falcon Global | Removed legal marker "Inc." || Blue Horizon  Media | Blue Horizon Media | Normalized internal spacing || Silverline Aerospace | Silverline Aerospace | Unique company, no variants |

In a second run (run/en.2.out.txt), the first two columns (raw name and canonical name) of all 40 rows matched run 1; only the wording of the Rationale column differed (such as "Normalized internal spacing" versus "Normalized double space").

[4] Validate the mapping output with a Python script. It checks only that the table has 40 data rows, that the two similar-name pairs stay separate, and that there are 28 canonical names. It never reads the original list, so it cannot tell whether column 1 matches the input or whether a key appears twice.

check_english.py
# -*- coding: utf-8 -*-import sys def parse_markdown_table(file_path):    with open(file_path, "r", encoding="utf-8") as f:        lines = f.readlines()    rows = []    for line in lines:        line = line.strip()        if not line.startswith("|"): continue        parts = [p.strip() for p in line.split("|")[1:-1]]        if not parts or all(set(p) <= set("-: ") for p in parts): continue        rows.append(parts)    return rows def verify(out_file):    rows = parse_markdown_table(out_file)    if not rows: sys.exit("Failed to parse table")    data = rows[1:]    errors = []    if len(data) != 40: errors.append(f"Row count mismatch: {len(data)} != 40")        mapping = {r[0]: r[1] for r in data if len(r) >= 2}        # Check separation of distinct similar entities    if mapping.get("Nova Energy") == mapping.get("Nova Capital"):        errors.append("Erroneous merge: Nova Energy == Nova Capital")    if mapping.get("Beacon Medical") == mapping.get("Beacon Robotics"):        errors.append("Erroneous merge: Beacon Medical == Beacon Robotics")            canonical_groups = set(mapping.values())    if len(canonical_groups) != 28:        errors.append(f"Group count mismatch: {len(canonical_groups)} != 28")     if errors:        for e in errors: print(f"FAIL: {e}")        sys.exit(1)    print(f"PASS: 40 rows mapped · {len(canonical_groups)} distinct canonical groups preserved")    sys.exit(0) if __name__ == "__main__":    verify(sys.argv[1])

Run the validation script against the output:

console
$ python run/check_english.py run/en.1.out.txtPASS: 40 rows mapped · 28 distinct canonical groups preserved

[5] Test the validator against intentional flaws. Introduce a synthetic faulty file run/en-bad-merge.txt where "Nova Energy" is incorrectly merged into "Nova Capital" (this is a synthetic test file, not model output).

console
$ python run/check_english.py run/en-bad-merge.txtFAIL: Erroneous merge: Nova Energy == Nova CapitalFAIL: Group count mismatch: 27 != 28

The script caught both the erroneous entity merger and the cluster count collapse to 27, exiting with status code 1.

[6] Map canonical names back into Excel. Paste the mapping table into columns A and B of a new sheet named Mapping, then apply XLOOKUP beside the raw customer column in the ledger sheet:

formula.txt
=XLOOKUP(A2, Mapping!$A$2:$A$41, Mapping!$B$2:$B$41, A2)

Put the standardized column in a PivotTable's row area, or use it as the criterion of SUMIFS, to total the split sales per company. Do not use Remove Duplicates for this: it does not add anything up, it keeps the first row and deletes the other matching rows (Microsoft). The lookup is only right when column 1 of the mapping table matches the ledger text exactly: a row whose key was rewritten (as in the Korean run 1 table) is not found and XLOOKUP returns the original value. Compare column 1 with the source list before using the table.

[7] Observed edge cases and mitigation.

  • Observed weakness (Korean run 1): for a raw name with a trailing space, the model wrote a different key in column 1 with an added note, and in run 2 it dropped the space, leaving a duplicate key. Either one breaks an exact-match XLOOKUP. The English runs did not show this.
  • What the checker misses: in the Korean runs, a rewritten key (the model appended a note like "(trailing space)" to a name) and a duplicated key both still got PASS, because the validator has no line-by-line comparison of column 1 against the original list. The English runs did not show this; the same gap exists in the English validator.
  • Mitigation: Add a strict constraint in the prompt rules: "Copy every raw company name into column 1 character-for-character with exact spacing preserved, without adding notes." No run with this rule was made, so whether it prevents the key rewrite was not tested.

#excel#deduplication#prompt#data-cleaning