How do you build AI lead scoring in n8n?

If your current lead scoring relies on rigid point systems or expensive enterprise tools, there is a middle path worth knowing about. n8n lets you connect a lead trigger, an AI model, and a CRM write-back in a single automated workflow, without per-seat pricing or black-box logic. This guide covers exactly how that workflow is built, from the trigger node to the final score landing in your CRM.
Contributed by
SaaS Hackers
No items found.
No items found.
Blog

Quick Answer: You can build an AI lead scoring workflow in n8n by connecting a trigger (form, webhook, or CRM event) to an AI node that evaluates each lead against your criteria, then writing the score and reasoning back to your CRM automatically. The whole workflow runs without human input and takes under an hour to set up.

Most lead scoring systems are either too rigid (fixed point values that ignore context) or too expensive (enterprise AI tools that charge per seat). n8n sits in the middle: a self-hostable automation platform where you wire together a trigger, an AI model, and a CRM write-back in a single workflow.

This guide walks through exactly how to build that workflow, from picking your trigger to prompting the AI and pushing scores back to HubSpot, Salesforce, or whichever CRM you use.

What Is AI Lead Scoring in n8n?

AI lead scoring in n8n is the process of using a large language model (LLM) node inside an n8n workflow to evaluate incoming lead data and assign a score based on criteria you define. Unlike rule-based scoring (where "company size > 100 = 10 points"), the AI reads the full context of a lead and reasons about fit the way a good SDR would.

The workflow has three core parts:

  • Trigger: Something that fires when a new lead arrives
  • AI scoring node: An LLM that reads lead data and returns a score plus reasoning
  • Write-back: A CRM node that updates the lead record with the score

What You Need Before You Start

Before building, confirm you have:

  • An n8n instance (cloud or self-hosted, version 1.0+)
  • An API key for an LLM (OpenAI, Google Gemini, or Anthropic Claude all work)
  • A CRM with API access (HubSpot, Salesforce, Pipedrive, or similar)
  • A defined lead source (Typeform, JotForm, webhook, or CRM trigger)
  • A written scoring rubric (your ICP criteria in plain English)

The scoring rubric is the part most people skip. Write it before you open n8n. It should cover the signals that matter to your business: industry, company size, job title, budget indicators, use case fit, and any disqualifying factors.

Step 1: Set Up Your Trigger Node

The trigger is what starts the workflow. Choose the one that matches where your leads first appear.

Option A: Webhook Trigger

Use this if your lead source can send a POST request (most form tools can). In n8n:

  1. Add a Webhook node as the first node
  2. Set the method to POST
  3. Copy the webhook URL and paste it into your form tool's submission endpoint
  4. Test it by submitting a dummy lead and confirming the data arrives in n8n

Option B: Form Tool Trigger (Typeform or JotForm)

  1. Add a Typeform or JotForm node
  2. Authenticate with your account
  3. Select the specific form you want to monitor
  4. Set the trigger to "On Form Submission"

Option C: CRM Trigger (New Lead in HubSpot)

  1. Add a HubSpot trigger node
  2. Set it to fire on "Contact Created" or "Deal Created"
  3. Authenticate and test

Whichever trigger you use, make sure the output includes the fields your AI node will need: company name, job title, company size, industry, and any freetext fields like "What's your main challenge?"

Step 2: Enrich the Lead Data (Optional but Recommended)

Raw form data is often thin. If your form only captures name, email, and company, the AI has limited signal to work with.

Add an enrichment step between your trigger and your AI node:

  • Clearbit or Apollo.io node: pulls company size, industry, tech stack, and funding data using the email domain
  • LinkedIn lookup via a tool like Phantombuster or Clay (connected via HTTP Request node)
  • HTTP Request node to your own data source if you have one

Map the enriched fields into a single object so the AI node receives everything in one clean input.

Step 3: Build the AI Scoring Node

This is where the scoring happens. n8n supports OpenAI, Anthropic, Google Gemini, and other LLMs natively through its AI nodes.

Setting Up the Node

  1. Add an AI Agent node or a basic OpenAI / Anthropic message node
  2. Connect your API credentials
  3. Choose your model (GPT-4o, Claude 3.5 Sonnet, and Gemini 1.5 Pro all handle structured output well)

Writing the System Prompt

The system prompt defines the AI's role and scoring logic. Here is a working template you can adapt:

You are a lead qualification expert for [Company Name].

Your job is to score inbound leads on a scale of 1 to 10 based on how well they match our ideal customer profile (ICP).

ICP criteria:
- Ideal industry: [e.g. B2B SaaS, professional services]
- Ideal company size: [e.g. 50-500 employees]
- Ideal job title: [e.g. Head of Sales, VP Revenue, Founder]
- Budget signal: [e.g. mentions budget, has funding, revenue above $1M]
- Use case fit: [e.g. looking to automate outbound, replace manual processes]

Disqualifiers (score 1-2 regardless of other signals):
- [e.g. student, freelancer with no team, competitor]

Scoring guide:
- 9-10: Strong ICP match, clear budget signal, decision-maker
- 7-8: Good ICP match, some gaps, worth a follow-up
- 5-6: Partial fit, nurture rather than immediate outreach
- 3-4: Weak fit, low priority
- 1-2: Disqualified

Return your response as valid JSON only, in this format:
{
  "score": [number 1-10],
  "tier": "[Hot / Warm / Cold / Disqualified]",
  "reasoning": "[2-3 sentence explanation of the score]",
  "recommended_action": "[e.g. Assign to AE immediately / Add to nurture sequence / Disqualify]"
}

Writing the User Message

In the user message field, reference the lead data using n8n expressions:

Score this lead:

Name: {{ $json.name }}
Email: {{ $json.email }}
Company: {{ $json.company }}
Job Title: {{ $json.job_title }}
Company Size: {{ $json.company_size }}
Industry: {{ $json.industry }}
Message / Use Case: {{ $json.message }}

Parsing the JSON Response

Add a Code node after the AI node to parse the JSON string into usable fields:

const aiResponse = $input.first().json.message.content;
const parsed = JSON.parse(aiResponse);

return [{
  json: {
    lead_score: parsed.score,
    lead_tier: parsed.tier,
    score_reasoning: parsed.reasoning,
    recommended_action: parsed.recommended_action
  }
}];

If the AI occasionally returns malformed JSON, wrap the parse in a try/catch and route failures to a Slack alert or manual review queue.

Step 4: Route Leads by Score

Before writing back to your CRM, add a routing step so different tiers trigger different actions.

  1. Add an IF node or Switch node after the Code node
  2. Set conditions based on lead_tier:
    • Hot (score 8-10): route to immediate CRM update + Slack notification to AE
    • Warm (score 5-7): route to CRM update + enrol in email sequence
    • Cold (score 3-4): route to CRM update + low-priority nurture tag
    • Disqualified (score 1-2): route to CRM update + mark as closed/lost

This routing logic means your sales team only sees the leads worth their time.

Step 5: Write the Score Back to Your CRM

This is the step that makes the workflow actually useful. A score sitting in n8n is worthless. It needs to live in your CRM where your team works.

HubSpot Write-Back

  1. Add a HubSpot node
  2. Set the operation to Update Contact
  3. Map the contact using the email from your trigger data
  4. Add custom property fields:
    • ai_lead_score{{ $json.lead_score }}
    • ai_lead_tier{{ $json.lead_tier }}
    • ai_score_reasoning{{ $json.score_reasoning }}
    • ai_recommended_action{{ $json.recommended_action }}

You will need to create these custom properties in HubSpot first. If you need outside help implementing CRM updates and lifecycle automation cleanly, it can be worth reviewing specialist B2B SaaS marketing ops agencies.

Salesforce Write-Back

  1. Add a Salesforce node
  2. Set operation to Update Lead or Update Contact
  3. Map the same fields to custom fields on the Lead object
  4. Use the lead's email or Salesforce ID as the lookup key

Pipedrive Write-Back

  1. Add a Pipedrive node
  2. Set operation to Update Person or Update Deal
  3. Map the score fields to custom fields you have created in Pipedrive

Step 6: Notify Your Team

A score in the CRM is good. A Slack message to the right AE is better for hot leads.

After the HubSpot write-back on the Hot branch:

  1. Add a Slack node
  2. Set the channel to your sales team channel or a direct message to the assigned rep
  3. Use a message template like:
🔥 New Hot Lead (Score: {{ $json.lead_score }}/10)

Name: {{ $('Trigger').item.json.name }}
Company: {{ $('Trigger').item.json.company }}
Title: {{ $('Trigger').item.json.job_title }}

AI Reasoning: {{ $json.score_reasoning }}
Recommended Action: {{ $json.recommended_action }}

View in HubSpot: [link]

How to Test Your Workflow Before Going Live

Do not activate the workflow without testing against real lead examples.

  1. Use n8n's Manual Trigger to run the workflow with static test data
  2. Test at least five lead profiles: one clear Hot, one clear Disqualified, and three edge cases
  3. Check that the AI output is valid JSON every time (if not, tighten the prompt)
  4. Confirm the CRM fields update correctly on each test contact
  5. Check the Slack notification fires only for Hot leads

Once all five pass, activate the workflow and monitor the first 20 live leads manually to confirm the scoring aligns with your team's judgment.

Common Problems and How to Fix Them

The AI returns text instead of JSON: Add "Return valid JSON only, no markdown, no explanation outside the JSON object" to the end of your system prompt.

Scores feel inconsistent: Your rubric is probably too vague. Add explicit examples to the system prompt: "A score of 9 means: Head of Sales at a 200-person SaaS company with a stated budget."

The CRM update fails: Check that your custom properties exist in the CRM before the workflow runs. n8n will error if the target field does not exist.

Enrichment data is missing: Build a fallback branch using an IF node that checks whether enrichment returned data. If it did not, pass the raw form data to the AI with a note in the prompt that enrichment was unavailable.

FAQs

What is AI lead scoring in n8n? AI lead scoring in n8n is a workflow where incoming lead data is passed to an LLM node, which evaluates the lead against your ICP criteria and returns a numeric score plus reasoning. The score is then written back to your CRM automatically, without any manual review step.

Which AI model works best for lead scoring in n8n? GPT-4o, Claude 3.5 Sonnet, and Gemini 1.5 Pro all produce reliable structured JSON output for lead scoring. GPT-4o is the most consistent at following strict JSON formatting instructions. Claude 3.5 Sonnet tends to write more nuanced reasoning. Either works well for this use case.

Can I use n8n AI lead scoring without a CRM? Yes. If you do not have a CRM, you can write scores to a Google Sheet instead. Add a Google Sheets node at the end of the workflow and append a new row with the lead data and score fields. This works as a lightweight alternative until you adopt a full CRM.

How do I stop the AI from scoring the same lead twice? Add a deduplication check before the AI node. Use a HubSpot or Airtable lookup to check whether a contact with that email already has a score. If it does, use an IF node to skip the AI step and end the workflow.

Is this workflow suitable for high lead volumes? n8n handles concurrent executions, so the workflow scales with your lead volume. The limiting factor is your LLM API rate limits. For volumes above 500 leads per day, add a Wait node or use n8n's queue mode to avoid hitting rate limits. If you are also comparing which tools to use for technical audits or workflow support around this setup, see this breakdown of Screamingfrog vs SEMRush vs AHREFS.

No items found.
AI

Find a B2B SaaS Expert

We've collected a directory of B2B SaaS experts and agencies that we've reviewed and categorised based on service and specialism for your review.

SaaS Hackers character line up

More from the blog