How to Build an AI Lead Enrichment Agent with n8n (Free Template)

How to Build an AI Lead Enrichment Agent with n8n (Free Template)

Sales teams waste 40% of their time researching leads manually. They copy-paste between LinkedIn, company websites, and CRMs, trying to piece together enough context for a personalized outreach. By the time they're ready to send that first email, the lead has gone cold. This AI lead enrichment agent solves that problem by automating the entire research workflow—from data collection to personalized email generation—in under 60 seconds per lead.

You'll learn how to build an n8n workflow that takes a raw lead list, enriches it with company and contact data, scores each lead using AI, and generates personalized outreach emails. The complete JSON template is available at the bottom of this article.

The Problem: Manual Lead Research Kills Sales Velocity

Sales reps spend 2-3 hours per day researching prospects before making first contact. They jump between multiple tools—LinkedIn Sales Navigator, company websites, Crunchbase, news sites—trying to gather enough information to write a relevant email. This manual process creates several critical problems.

Current challenges:

  • Inconsistent data quality across the sales team
  • 2-3 hours daily per rep spent on manual research
  • Low personalization quality due to time constraints
  • Leads go cold while waiting for outreach
  • No systematic lead scoring or prioritization

Business impact:

  • Time spent: 10-15 hours per week per sales rep
  • Opportunity cost: 30-40% fewer qualified conversations
  • Conversion rate: 2-3% on generic outreach vs 8-12% on personalized
  • Revenue leakage: Reps contact wrong-fit leads due to incomplete data

The core issue isn't lack of data—it's the manual effort required to collect, synthesize, and act on that data at scale.

The Solution Overview

This n8n AI agent automates the complete lead enrichment pipeline using a multi-stage workflow. It starts with a raw lead list (name and company), enriches each contact with professional and company data, uses AI to analyze fit and generate talking points, then creates personalized outreach emails.

The workflow combines Perplexity AI for web research, OpenAI for analysis and content generation, and conditional logic to handle data quality issues. It processes leads in batches, handles API rate limits gracefully, and outputs enriched data ready for your CRM or email tool. The entire process runs in 45-90 seconds per lead depending on data availability.

What You'll Build

This AI lead enrichment agent delivers a complete research-to-outreach automation system. Here's what the workflow accomplishes:

Component Technology Purpose
Data Input Manual Trigger / Webhook Accept lead lists with name and company
Contact Enrichment Perplexity AI (Sonar Model) Find LinkedIn profiles, job titles, and professional background
Company Research Perplexity AI (Sonar Model) Gather company size, industry, recent news, and tech stack
Lead Scoring OpenAI GPT-4 Analyze fit based on ICP criteria and assign priority score
Personalization Engine OpenAI GPT-4 Generate custom talking points and pain point hypotheses
Email Generation OpenAI GPT-4 Create personalized outreach emails with relevant context
Output Formatting n8n Set Nodes Structure data for CRM import or email tools

Key capabilities:

  • Enriches 50-100 leads per hour (depending on API rate limits)
  • Finds contact information with 75-85% accuracy
  • Generates unique talking points for each lead
  • Scores leads on 1-10 scale based on your ICP criteria
  • Creates email drafts ready for review and sending
  • Handles missing data gracefully with fallback logic

Prerequisites

Before building this workflow, ensure you have:

  • n8n instance (cloud or self-hosted version 1.0+)
  • Perplexity AI API key with access to Sonar model
  • OpenAI API key with GPT-4 access
  • Basic understanding of JSON data structures
  • Your ideal customer profile (ICP) criteria documented
  • Sample lead list with at least name and company fields

Optional but recommended:

  • CRM integration (HubSpot, Salesforce, or Airtable)
  • Email service provider API access (for automated sending)
  • Webhook endpoint for triggering from external systems

Step 1: Set Up the Data Input Layer

The workflow begins with a manual trigger that accepts lead data. This trigger can be replaced with a webhook, Google Sheets integration, or CRM connection depending on your lead source.

Configure the Manual Trigger node:

  1. Add a Manual Trigger node as your workflow entry point
  2. In the "Execute Workflow" settings, configure to accept JSON input
  3. Structure your input data with these required fields: firstName, lastName, company

Input data structure:

{
  "leads": [
    {
      "firstName": "John",
      "lastName": "Smith",
      "company": "Acme Corp"
    }
  ]
}

Why this works:
The manual trigger provides flexibility during development and testing. You can paste sample leads directly into the workflow to verify each stage before connecting to production data sources. The JSON structure keeps data clean and makes it easy to add optional fields like industry or linkedInUrl later.

Step 2: Enrich Contact Information with AI

The first enrichment stage uses Perplexity AI to find professional information about each lead. This replaces manual LinkedIn searches and provides structured data about the person's role and background.

Configure the Perplexity Contact Enrichment node:

  1. Add an HTTP Request node after your trigger
  2. Set method to POST
  3. URL: https://api.perplexity.ai/chat/completions
  4. Add Authentication header with your Perplexity API key

Node configuration:

{
  "model": "sonar",
  "messages": [
    {
      "role": "system",
      "content": "You are a professional researcher. Find accurate, current information about business professionals."
    },
    {
      "role": "user",
      "content": "Find professional information for {{$json.firstName}} {{$json.lastName}} at {{$json.company}}. Return: current job title, LinkedIn URL, years of experience, department, and 2-3 sentence professional summary."
    }
  ],
  "temperature": 0.2
}

Why this approach:
Perplexity's Sonar model searches the real-time web and returns structured information with source citations. The low temperature (0.2) ensures consistent, factual responses rather than creative interpretations. The prompt explicitly requests structured fields, making it easier to parse the response in downstream nodes.

Add a Code node to parse the response:

const response = $input.item.json.choices[0].message.content;

// Extract structured data from AI response
const jobTitle = response.match(/Job Title: (.+)/)?.[1] || "Not found";
const linkedIn = response.match(/LinkedIn: (.+)/)?.[1] || "";
const experience = response.match(/Experience: (.+)/)?.[1] || "";

return {
  ...item.json,
  jobTitle,
  linkedInUrl: linkedIn,
  yearsExperience: experience
};

This parsing logic handles cases where Perplexity can't find certain fields, preventing workflow failures from missing data.

Step 3: Research Company Information

The second enrichment stage gathers company-level data that informs lead scoring and personalization. This replaces manual research across company websites, Crunchbase, and news sites.

Configure the Perplexity Company Research node:

  1. Add another HTTP Request node
  2. Use the same Perplexity API endpoint
  3. Modify the prompt to focus on company intelligence

Node configuration:

{
  "model": "sonar",
  "messages": [
    {
      "role": "system",
      "content": "You are a business intelligence researcher. Provide factual, current information about companies."
    },
    {
      "role": "user",
      "content": "Research {{$json.company}}. Return: company size (employees), industry, headquarters location, recent news (last 30 days), technology stack, and funding status. Format as structured data."
    }
  ],
  "temperature": 0.2
}

Parse company data with a Code node:

const response = $input.item.json.choices[0].message.content;

return {
  ...item.json,
  companySize: response.match(/Size: (.+)/)?.[1] || "Unknown",
  industry: response.match(/Industry: (.+)/)?.[1] || "",
  recentNews: response.match(/Recent News: (.+)/)?.[1] || "No recent news",
  techStack: response.match(/Technology: (.+)/)?.[1] || ""
};

Why this works:
Separating contact and company research into two API calls improves accuracy. Each prompt has a focused scope, reducing hallucination risk. The structured output format makes downstream processing predictable and reliable.

Step 4: Score Leads with AI Analysis

Now that you have enriched data, use OpenAI to analyze lead fit against your ideal customer profile. This replaces manual qualification and ensures consistent scoring across all leads.

Configure the OpenAI Lead Scoring node:

  1. Add an HTTP Request node for OpenAI API
  2. URL: https://api.openai.com/v1/chat/completions
  3. Add your OpenAI API key to Authentication header

Node configuration:

{
  "model": "gpt-4",
  "messages": [
    {
      "role": "system",
      "content": "You are a sales qualification expert. Score leads from 1-10 based on fit criteria."
    },
    {
      "role": "user",
      "content": "Score this lead:

Name: {{$json.firstName}} {{$json.lastName}}
Title: {{$json.jobTitle}}
Company: {{$json.company}}
Size: {{$json.companySize}}
Industry: {{$json.industry}}

ICP Criteria:
- Target titles: VP Sales, Director Marketing, Head of Growth
- Company size: 50-500 employees
- Industries: SaaS, Technology, Professional Services

Return: Score (1-10), reasoning (2 sentences), and priority level (High/Medium/Low)."
    }
  ],
  "temperature": 0.3
}

Parse scoring results:

const response = $input.item.json.choices[0].message.content;

const score = parseInt(response.match(/Score: (\d+)/)?.[1] || "5");
const reasoning = response.match(/Reasoning: (.+)/)?.[1] || "";
const priority = response.match(/Priority: (\w+)/)?.[1] || "Medium";

return {
  ...item.json,
  leadScore: score,
  scoreReasoning: reasoning,
  priority
};

Why this approach:
GPT-4's reasoning capabilities allow it to weigh multiple factors simultaneously—job title relevance, company size fit, industry match, recent company news. The explicit ICP criteria in the prompt ensure consistent scoring logic. The temperature of 0.3 balances consistency with nuanced evaluation.

Step 5: Generate Personalized Talking Points

With scored leads, create custom talking points that sales reps can use in outreach. This replaces generic templates with context-specific insights.

Configure the OpenAI Personalization node:

{
  "model": "gpt-4",
  "messages": [
    {
      "role": "system",
      "content": "You are a sales research assistant. Generate specific, relevant talking points for outreach."
    },
    {
      "role": "user",
      "content": "Create 3 personalized talking points for reaching out to {{$json.firstName}} {{$json.lastName}} ({{$json.jobTitle}}) at {{$json.company}}.

Context:
- Company size: {{$json.companySize}}
- Industry: {{$json.industry}}
- Recent news: {{$json.recentNews}}
- Tech stack: {{$json.techStack}}

Our solution: [Insert your product description]

Return 3 talking points that connect their situation to our solution. Be specific, not generic."
    }
  ],
  "temperature": 0.7
}

Parse talking points:

const response = $input.item.json.choices[0].message.content;

// Extract numbered talking points
const points = response.match(/\d+\.\s+(.+)/g) || [];

return {
  ...item.json,
  talkingPoints: points.map(p => p.replace(/^\d+\.\s+/, ''))
};

Why this works:
The higher temperature (0.7) allows for more creative, varied talking points while staying grounded in the provided context. Including recent news and tech stack in the prompt enables truly personalized insights rather than generic industry observations.

Step 6: Generate Outreach Emails

The final stage creates complete email drafts using all enriched data and talking points. These emails are ready for rep review and sending.

Configure the OpenAI Email Generation node:

{
  "model": "gpt-4",
  "messages": [
    {
      "role": "system",
      "content": "You are an expert sales copywriter. Write personalized, concise outreach emails."
    },
    {
      "role": "user",
      "content": "Write a personalized outreach email to {{$json.firstName}} {{$json.lastName}} ({{$json.jobTitle}}) at {{$json.company}}.

Talking points:
{{$json.talkingPoints.join('
')}}

Email requirements:
- Subject line (under 50 characters)
- 3-4 short paragraphs
- One clear call-to-action
- Professional but conversational tone
- Reference specific context about their company

Return: Subject line and email body separately."
    }
  ],
  "temperature": 0.8
}

Parse email output:

const response = $input.item.json.choices[0].message.content;

const subject = response.match(/Subject: (.+)/)?.[1] || "Quick question about {{$json.company}}";
const body = response.replace(/Subject: .+

/, '');

return {
  ...item.json,
  emailSubject: subject,
  emailBody: body,
  enrichmentComplete: true,
  enrichedAt: new Date().toISOString()
};

Workflow Architecture Overview

This workflow consists of 12 nodes organized into 5 main processing stages:

  1. Data ingestion (Node 1): Manual trigger accepts lead list with name and company
  2. Contact enrichment (Nodes 2-3): Perplexity AI finds professional information, Code node parses response
  3. Company research (Nodes 4-5): Perplexity AI gathers company data, Code node structures output
  4. Lead scoring (Nodes 6-7): OpenAI analyzes fit against ICP, Code node extracts score and priority
  5. Personalization (Nodes 8-11): OpenAI generates talking points and email drafts, Code nodes format output
  6. Output delivery (Node 12): Set node structures final data for export

Execution flow:

  • Trigger: Manual execution or webhook from CRM/lead source
  • Average run time: 45-90 seconds per lead (depending on API response times)
  • Key dependencies: Perplexity AI API, OpenAI API with GPT-4 access

Critical nodes:

  • HTTP Request (Perplexity): Handles web research for contact and company data
  • HTTP Request (OpenAI): Processes lead scoring, talking points, and email generation
  • Code nodes: Parse AI responses and handle missing data gracefully
  • Set node: Formats enriched data for CRM import or email tools

The complete n8n workflow JSON template is available at the bottom of this article.

Key Configuration Details

Perplexity API Settings

Required fields:

  • API Key: Your Perplexity API key (get from perplexity.ai/settings)
  • Model: Use "sonar" for real-time web search capabilities
  • Temperature: 0.2 for factual research, 0.7 for creative content

Common issues:

  • Rate limits: Perplexity free tier allows 5 requests/minute → Add Wait node between calls
  • Timeout errors: Set HTTP Request timeout to 60 seconds for complex research queries
  • Parsing failures: Always include fallback values in Code nodes for missing data

OpenAI API Settings

Required fields:

  • API Key: Your OpenAI API key with GPT-4 access
  • Model: "gpt-4" for best reasoning (or "gpt-4-turbo" for faster/cheaper)
  • Temperature: 0.3 for scoring, 0.7 for talking points, 0.8 for email generation

Why this approach:
Different workflow stages require different creativity levels. Lead scoring needs consistency (low temperature), while email generation benefits from variety (higher temperature). Using GPT-4 instead of GPT-3.5 significantly improves reasoning quality for lead scoring and context understanding.

Variables to customize:

In the lead scoring prompt, modify these ICP criteria to match your business:

  • targetTitles: List of decision-maker titles you sell to
  • companySize: Employee count range that fits your solution
  • industries: Vertical markets you serve
  • disqualifiers: Criteria that automatically lower scores (e.g., "competitors", "wrong geography")

In the email generation prompt, customize:

  • productDescription: Your solution's value proposition
  • emailLength: Adjust paragraph count for your sales process
  • ctaType: Change call-to-action (demo request, meeting, resource download)

Testing & Validation

Test each enrichment stage independently:

  1. Contact enrichment: Run workflow with 3-5 known contacts from your network. Verify LinkedIn URLs and job titles match reality. Accuracy should be 75-85%.

  2. Company research: Test with companies of varying sizes (startup, mid-market, enterprise). Check that company size and industry classifications are accurate.

  3. Lead scoring: Score 10 leads manually using your ICP criteria, then compare to AI scores. Scores should align within ±2 points.

  4. Email quality: Generate 20 emails and have sales reps review. Check for:

    • Factual accuracy (no hallucinated details)
    • Relevant talking points (not generic)
    • Appropriate tone for your brand
    • Clear, actionable CTA

Common troubleshooting:

Issue Cause Solution
"API key invalid" error Wrong API key format or expired key Regenerate key in provider dashboard, update in n8n credentials
Workflow times out Too many leads processed at once Add Split In Batches node, process 10 leads at a time
Inconsistent data quality Vague prompts to AI models Make prompts more specific, add examples of desired output format
Missing enrichment data Lead name/company too generic Add validation node to check data quality before enrichment

Validation checklist before production:

  • Test with 50+ leads to verify error handling
  • Confirm API costs align with budget (typically $0.10-0.30 per lead)
  • Verify output format matches your CRM import requirements
  • Test webhook trigger if using automated lead flow
  • Set up error notifications (email or Slack) for failed enrichments

Production Deployment Checklist

Area Requirement Why It Matters
Error Handling Add Error Trigger node with retry logic Prevents data loss when APIs fail or rate limits hit
Rate Limiting Insert Wait nodes between API calls (12 seconds) Avoids hitting Perplexity's 5 req/min limit
Monitoring Add webhook to log completion status Detect failures within minutes vs discovering days later
Data Validation Add IF nodes to check required fields exist Prevents wasted API calls on incomplete lead data
Cost Control Set maximum leads per execution (100) Caps API costs at predictable level per run
Output Storage Connect to Google Sheets or Airtable Creates audit trail and backup of enriched data

Production setup requirements:

  1. Environment variables: Store API keys in n8n credentials, not hardcoded in nodes
  2. Execution limits: Set workflow timeout to 15 minutes for large batches
  3. Logging: Add Set nodes after each stage to log progress for debugging
  4. Notifications: Configure Slack or email alerts for workflow failures

Customization ideas for your sales process:

  • Add Salesforce/HubSpot nodes to write enriched data directly to CRM
  • Connect to Instantly.ai or Lemlist to send emails automatically
  • Add a human approval step before email sending (use Wait for Webhook node)
  • Integrate with Slack to notify reps when high-priority leads are enriched
  • Add a Google Sheets output for manual review before CRM import

Use Cases & Variations

Use Case 1: Inbound Lead Qualification

  • Industry: B2B SaaS companies with high inbound volume
  • Scale: 200-500 new leads per week from website, ads, events
  • Modifications needed: Replace manual trigger with webhook from form submissions, add real-time Slack notifications for hot leads (score 8+), reduce email generation (reps handle outreach)

Use Case 2: Outbound Prospecting at Scale

  • Industry: Sales agencies, SDR teams doing cold outreach
  • Scale: 1,000+ prospects per week from LinkedIn, Apollo, ZoomInfo
  • Modifications needed: Add Split In Batches node (50 leads per batch), increase Wait times between API calls to avoid rate limits, connect to email sequencing tool for automated sending

Use Case 3: Account-Based Marketing (ABM)

  • Industry: Enterprise sales teams targeting specific accounts
  • Scale: 20-50 high-value accounts with 5-10 contacts each
  • Modifications needed: Add company-level research (funding, tech stack, org chart), generate account-specific talking points, create multi-touch email sequences, integrate with 6sense or Demandbase for intent data

Use Case 4: Event Follow-Up Automation

  • Industry: Companies attending trade shows, conferences, webinars
  • Scale: 100-300 leads collected per event
  • Modifications needed: Add event context to prompts ("met at [Event Name]"), prioritize leads based on session attendance, generate follow-up emails referencing specific conversations, integrate with event management platforms

Use Case 5: Partner/Referral Lead Processing

  • Industry: Companies with partner networks or referral programs
  • Scale: 50-100 referred leads per month
  • Modifications needed: Add referral source tracking, customize email tone for warm introductions, include partner name in talking points, create co-branded email templates

Customizations & Extensions

Alternative Integrations

Instead of Perplexity AI:

  • Clearbit API: Best for B2B contact enrichment with higher accuracy (85-90%) but costs $0.50-1.00 per lookup - replace Perplexity nodes with HTTP Request to Clearbit endpoints
  • Apollo.io API: Better if you need phone numbers and direct dials - swap Perplexity nodes for Apollo enrichment calls, add phone number fields to output
  • Clay.com: Use when you need waterfall enrichment (tries multiple data sources) - replace enrichment section with Clay webhook integration

Instead of OpenAI:

  • Anthropic Claude: Better for longer context windows (useful for analyzing multiple news articles) - swap OpenAI HTTP nodes with Anthropic API calls, increase context in prompts
  • Google Gemini: More cost-effective for high-volume processing - replace OpenAI nodes with Gemini API, adjust temperature settings (Gemini uses 0-1 scale)

Workflow Extensions

Add automated email sending:

  • Add Gmail or SendGrid nodes after email generation
  • Connect to email warm-up service (Mailshake, Instantly) for deliverability
  • Implement send time optimization (avoid weekends, optimize by timezone)
  • Nodes needed: +4 (IF for send time logic, Gmail/SendGrid, Set for tracking)

Scale to handle enterprise volumes:

  • Replace manual trigger with Supabase/PostgreSQL for lead queue management
  • Add Redis caching layer to avoid re-enriching same companies
  • Implement parallel processing (split workflow into sub-workflows)
  • Performance improvement: Process 500+ leads per hour vs 50-100

Add lead nurturing sequences:

  • Connect to email marketing platform (Mailchimp, HubSpot, ActiveCampaign)
  • Generate multi-touch sequences (3-5 emails) based on lead score
  • Add conditional logic for different nurture paths by industry/role
  • Track engagement and re-score leads based on email opens/clicks

Integration possibilities:

Add This To Get This Complexity
Slack notifications Real-time alerts for high-priority leads (score 8+) Easy (2 nodes)
Google Sheets logging Audit trail and manual review queue Easy (3 nodes)
Salesforce/HubSpot sync Write enriched data directly to CRM Medium (5-7 nodes)
Zapier webhook Connect to 5,000+ apps without custom integrations Easy (2 nodes)
Airtable database Better data visualization and team collaboration Medium (4 nodes)
Calendly integration Auto-book meetings for qualified leads Medium (6 nodes)

Advanced customizations:

Add competitive intelligence:

  • Use Perplexity to research competitor mentions in target accounts
  • Generate talking points that position against competitors
  • Track competitive wins/losses in CRM
  • Nodes needed: +3 (HTTP Request for research, Code for parsing, Set for formatting)

Implement lead recycling:

  • Add IF node to check lead age and previous contact attempts
  • Re-enrich leads after 90 days with fresh company news
  • Adjust messaging based on previous outreach history
  • Nodes needed: +5 (IF conditions, date comparison logic, updated prompts)

Create executive summary reports:

  • Add Schedule node to run weekly digest
  • Aggregate lead scores, enrichment success rates, top industries
  • Generate summary with GPT-4 and send to sales leadership
  • Nodes needed: +8 (Schedule, aggregate functions, GPT-4 summary, email delivery)

Get Started Today

Ready to automate your lead enrichment process?

  1. Download the template: Scroll to the bottom of this article to copy the complete n8n workflow JSON
  2. Import to n8n: Go to Workflows → Import from URL or File, paste the JSON
  3. Configure your API keys: Add credentials for Perplexity AI and OpenAI in n8n settings
  4. Customize ICP criteria: Update the lead scoring prompt with your ideal customer profile
  5. Test with sample leads: Run the workflow with 5-10 known contacts to verify accuracy
  6. Deploy to production: Connect to your lead source (CRM, webhook, or Google Sheets) and activate

Expected results after deployment:

  • 80-90% reduction in manual research time per lead
  • 3-5x increase in personalized outreach volume
  • 2-3x improvement in email response rates
  • Consistent lead scoring across your entire sales team

Need help customizing this workflow for your specific sales process? Schedule an intro call with Atherial at atherial.ai/contact to discuss your lead enrichment requirements and get expert guidance on optimizing this workflow for your business.