Deduplicate CSV leads and rank key contacts with OpenRouter Claude Haiku

Go to Workflow
0 views
Built by Fafa Modey Fafa Modey
Created on August 31, 2026

Description

Quick overview
This workflow accepts a uploaded CSV/XLSX leads file, groups rows by organization, and deduplicates to one contact per company. If multiple named contacts exist, it calls OpenRouter (chat completions) to pick the most senior person, then exports a cleaned CSV plus a JSON cleanup report.

How it works
Receives a leads file upload and a “Max Rows in Cleaned CSV” limit via an n8n Form trigger.
Extracts rows from the uploaded spreadsheet and groups them by organization, deduping repeated people/roles and marking entries as Named or Generic when no person name exists.
Limits processing to the first N organizations (based on your configured max rows) while a separate branch computes a full-file summary report.
Routes organizations with a single candidate contact directly to the output without using AI.
Sends organizations with multiple candidate contacts to OpenRouter to select the most senior contact, then matches the returned number back to the chosen row.
Merges the AI-selected and directly selected contacts into one dataset and converts it to a cleaned_leads.csv file.
Converts the summary metrics into a cleanup_report.json file.

Setup
Create an OpenRouter API key and add it to n8n as an HTTP Header Auth credential (Authorization: Bearer YOUR_KEY) used by the OpenRouter request.
In the Configuration step, set the correct Excel sheet name (if using XLSX) and choose the OpenRouter model ID you want to use.
Upload a CSV/XLSX file that includes an organization/company column and (optionally) name and job title columns that match the workflow’s header detection logic (or adjust the header hints in the grouping code).

Nodes Used (2)

Code
n8n-nodes-base.code
HTTP Request
n8n-nodes-base.httpRequest