{
  "id": "BO6rg06cB3iYFklp",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "AI Lead Enricher and Qualifier",
  "tags": [],
  "nodes": [
    {
      "id": "0001310b-fb16-45f9-ac87-3f908b7d9015",
      "name": "Azure OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
      "position": [
        352,
        224
      ],
      "parameters": {
        "model": "openai",
        "options": {}
      },
      "credentials": {
        "azureOpenAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2cc3997d-30a6-4f68-a8b3-5d08f6c78641",
      "name": "MCP Client",
      "type": "@n8n/n8n-nodes-langchain.mcpClientTool",
      "position": [
        512,
        240
      ],
      "parameters": {
        "options": {},
        "endpointUrl": "https://mcp.brightdata.com/mcp?token=YOUR_TOKEN_HERE"
      },
      "typeVersion": 1.2
    },
    {
      "id": "f487f3b1-ece3-431d-bd75-7adb84ee45f0",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        656,
        240
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"contact\": {\n    \"jobtitle\": \"\",\n    \"linkedin_profile\": \"\",\n    \"country\": \"\"\n  },\n  \"company\": {\n    \"company_name\": \"\",\n    \"description\": \"\",\n    \"industry\": \"\",\n    \"numberofemployees\": \"\",\n    \"annualrevenue\": \"\",\n    \"linkedin_company_page\": \"\",\n    \"hq_country\": \"\",\n    \"hq_city\": \"\",\n    \"funding_raised\":\"\"\n\n  }\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "b2739a50-06f0-4cd5-a2ed-1a421ea115d4",
      "name": "Create or update a contact",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        1504,
        -16
      ],
      "parameters": {
        "email": "={{ $('On form submission').item.json.Email }}",
        "options": {},
        "authentication": "appToken",
        "additionalFields": {
          "country": "={{ $('Lead Enricher Agent').item.json.output.contact.country }}",
          "jobTitle": "={{ $('Lead Enricher Agent').item.json.output.contact.jobtitle }}",
          "companyName": "={{ $('Lead Enricher Agent').item.json.output.company.company_name }}",
          "linkedinUrl": "={{ $('Lead Enricher Agent').item.json.output.contact.linkedin_profile }}"
        }
      },
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f55f2271-2302-4161-80fd-7c70276f694f",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        80,
        -64
      ],
      "parameters": {
        "options": {},
        "formTitle": "Lead Form",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Name",
              "requiredField": true
            },
            {
              "fieldType": "email",
              "fieldLabel": "Email",
              "requiredField": true
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "6d871e5b-6df8-43b5-8ce6-b3957aebc84b",
      "name": "Azure OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
      "position": [
        960,
        176
      ],
      "parameters": {
        "model": "openai",
        "options": {}
      },
      "credentials": {
        "azureOpenAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2f6cfb0a-0ffb-4b2f-a183-091c0b5dc125",
      "name": "Lead Enricher Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        416,
        -64
      ],
      "parameters": {
        "text": "=Below is all currently available information about the contact and the company:\n\nContact:\n- Name: {{ $json.Name }}\n- Email: {{ $json.Email }}\n\nCompany:\n- Name: Get it from the email domain\n- Website: Extract from the email\n\nIf ANY of the following fields are missing or confidence is low, CALL the Bright MCP tool\n\nSuggested queries:\n- \" Company Name LinkedIn\"\n- \" Company Name industry\"\n- \" Company Name description\"\n- \" Company Name number of employees\"\n- \" Company Name headquarters\"\n- \" Company Name funding\"\n- \"{{ $json.Name }} job title\"\n- \"{{ $json.Name }} LinkedIn\" ",
        "options": {
          "systemMessage": "You are a B2B CRM data enrichment assistant.  \nYou enrich business records ONLY with verifiable information.\n\nYou have access to a tool called Bright Data MCP which allows you to search the public web for reliable information.\n\nRules:\n- When a required field cannot be completed with high confidence from the user-provided input, you MUST call the `bright_data_mcp.search` tool.\n- After receiving Bright Data MCP results, extract reliable information and discard marketing fluff.\n- If after using the tool you are still NOT confident, return an empty string \"\" for that field.\n- Never hallucinate values. Never guess estimated revenues, industries, or social links.\n- Never output explanations or reasoning.\n- Output ONLY a single JSON object using the specified schema.\n"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "112f9021-6953-4381-a354-552ce955abfd",
      "name": "Lead Scoring Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        960,
        -64
      ],
      "parameters": {
        "text": "=You will receive a JSON object with the following structure.\nThis data is already enriched by another agent:\n\n{\n  \"contact\": {\n    \"jobtitle\": \"\",\n    \"linkedin_profile\": \"\",\n    \"country\": \"\"\n  },\n  \"company\": {\n    \"company_name\": \"\",\n    \"description\": \"\",\n    \"industry\": \"\",\n    \"numberofemployees\": \"\",\n    \"annualrevenue\": \"\",\n    \"linkedin_company_page\": \"\",\n    \"hq_country\": \"\",\n    \"hq_city\": \"\",\n    \"funding_raised\": \"\"\n  }\n}\n\nHere is the actual JSON for this lead:\n\n{{JSON.stringify($json)}}\n\nUsing ONLY this data, calculate a single numeric Fit Score from 0 to 100.\n\nGuidelines (for a B2B automation / AI / RevOps agency focused on SaaS & tech):\n- Higher score if:\n  - Industry suggests SaaS, software, tech, fintech, online services, agencies, or other B2B businesses.\n  - numberofemployees suggests a growing or established company (e.g. 10\u20132000 employees).\n  - jobtitle indicates a decision-maker or operational role (e.g. Founder, CEO, COO, VP, Head of Operations, RevOps, CTO).\n  - funding_raised is significant or clearly indicates growth potential.\n- Moderate score if:\n  - Industry is unclear but company description hints at B2B or online business.\n  - Company is small but appears serious and funded.\n- Lower score if:\n  - Very small company (1\u20132 employees) and no clear growth/funding.\n  - Industry is clearly a poor fit or unrelated to B2B tech/automation.\n  - Almost all fields are empty or generic.\n\nEven if data is incomplete, still return your best conservative Fit Score.\n\nWhere \"fit_score\" is a number between 0 and 100 (no quotes).\nDo NOT include any other fields or text.\n",
        "options": {
          "systemMessage": "You are a B2B lead scoring assistant for a CRM.\n\nYou receive structured data for a contact and their company that has ALREADY been enriched by another system. \nYour job is ONLY to calculate a single Fit Score from 0 to 100 based on how attractive this lead is for a B2B automation / AI / RevOps agency focused on SaaS and tech companies.\n\nImportant:\n- Do NOT perform any enrichment.\n- Do NOT change, correct, or invent any of the input fields.\n- Do NOT add new fields.\n- Use ONLY the data provided to you.\n- If data is sparse or missing, still give your best conservative Fit Score.\n- Do NOT output explanations or narrative text.\n- Return ONLY the JSON object requested in the user prompt, with \"fit_score\" as a number (not a string).\n"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "b870dd5d-743b-4e96-95db-c04f429bab7a",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        1248,
        -64
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "2d61ca01-98f9-4181-b3dc-320e23bad0eb",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.output.fit_score }}",
              "rightValue": 70
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "8e524f40-8b15-4bd0-a713-fa92e091fdfb",
      "name": "Send a message",
      "type": "n8n-nodes-base.slack",
      "position": [
        2096,
        -16
      ],
      "parameters": {
        "text": "=New Lead:  {{ $('On form submission').item.json.Name }}\nEmail: {{ $('On form submission').item.json.Email}}\nJob Title:{{ $('Lead Enricher Agent').item.json.output.contact.jobtitle }}\nLinkedin:{{ $('Lead Enricher Agent').item.json.output.contact.linkedin_profile }}\nCountry:{{ $('Lead Enricher Agent').item.json.output.contact.country }}",
        "user": {
          "__rl": true,
          "mode": "list",
          "value": "U09U6MMQ7H8",
          "cachedResultName": "sparsh"
        },
        "select": "user",
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "20375113-6d4a-4d88-a587-d29b539f8522",
      "name": "Structured Output Parser1",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1152,
        160
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"fit_score\": 0\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "12ab6256-cdb5-43e4-8c24-330764133c0b",
      "name": "Create or update a contact1",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        1584,
        288
      ],
      "parameters": {
        "email": "={{ $('On form submission').item.json.Email }}",
        "options": {},
        "authentication": "appToken",
        "additionalFields": {
          "country": "={{ $('Lead Enricher Agent').item.json.output.contact.country }}",
          "jobTitle": "={{ $('Lead Enricher Agent').item.json.output.contact.jobtitle }}",
          "companyName": "={{ $('Lead Enricher Agent').item.json.output.company.company_name }}",
          "linkedinUrl": "={{ $('Lead Enricher Agent').item.json.output.contact.linkedin_profile }}"
        }
      },
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "59b67a1f-8114-490e-aec4-62d7978cd5c3",
      "name": "Update a company2",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        1920,
        -16
      ],
      "parameters": {
        "resource": "company",
        "companyId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.companyId }}"
        },
        "operation": "update",
        "updateFields": {
          "city": "={{ $('Lead Enricher Agent').item.json.output.company.hq_city }}",
          "description": "={{ $('Lead Enricher Agent').item.json.output.company.description }}",
          "annualRevenue": "={{ $('Lead Enricher Agent').item.json.output.company.annualrevenue }}",
          "countryRegion": "={{ $('Lead Enricher Agent').item.json.output.company.hq_country }}",
          "totalMoneyRaised": "={{ $('Lead Enricher Agent').item.json.output.company.funding_raised }}",
          "customPropertiesUi": {
            "customPropertiesValues": [
              {
                "value": "={{ $('Lead Enricher Agent').item.json.output.company.numberofemployees }}",
                "property": "company_size"
              },
              {
                "value": "={{ $('Lead Enricher Agent').item.json.output.company.industry }}",
                "property": "industry_name"
              }
            ]
          },
          "linkedInCompanyPage": "={{ $('Lead Enricher Agent').item.json.output.company.linkedin_company_page }}"
        },
        "authentication": "appToken"
      },
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "8675da2f-b9dd-4b5b-98f6-d56deddf791d",
      "name": "Search for a company by Domain",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        1712,
        -16
      ],
      "parameters": {
        "domain": "={{ $json.properties.hs_email_domain.value }}",
        "options": {},
        "resource": "company",
        "operation": "searchByDomain",
        "authentication": "appToken"
      },
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "b7934ba1-ad5e-43c8-9ff3-07d3bd64f9f0",
      "name": "Search for a company by Domain1",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        1824,
        288
      ],
      "parameters": {
        "domain": "={{ $json.properties.hs_email_domain.value }}",
        "options": {},
        "resource": "company",
        "operation": "searchByDomain",
        "authentication": "appToken"
      },
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "b9f0bdc7-29b9-4b83-9648-f8cdc0419d51",
      "name": "Update a company",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        2048,
        288
      ],
      "parameters": {
        "resource": "company",
        "companyId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.companyId }}"
        },
        "operation": "update",
        "updateFields": {
          "city": "={{ $('Lead Enricher Agent').item.json.output.company.hq_city }}",
          "description": "={{ $('Lead Enricher Agent').item.json.output.company.description }}",
          "annualRevenue": "={{ $('Lead Enricher Agent').item.json.output.company.annualrevenue }}",
          "countryRegion": "={{ $('Lead Enricher Agent').item.json.output.company.hq_country }}",
          "totalMoneyRaised": "={{ $('Lead Enricher Agent').item.json.output.company.funding_raised }}",
          "customPropertiesUi": {
            "customPropertiesValues": [
              {
                "value": "={{ $('Lead Enricher Agent').item.json.output.company.numberofemployees }}",
                "property": "company_size"
              },
              {
                "value": "={{ $('Lead Enricher Agent').item.json.output.company.industry }}",
                "property": "industry_name"
              }
            ]
          },
          "linkedInCompanyPage": "={{ $('Lead Enricher Agent').item.json.output.company.linkedin_company_page }}"
        },
        "authentication": "appToken"
      },
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "4f1d0d32-8b99-4894-9f1a-d5d7291f85cd",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        304,
        -144
      ],
      "parameters": {
        "color": 5,
        "width": 496,
        "height": 544,
        "content": "## Lead Enrichment using Bright Data MCP"
      },
      "typeVersion": 1
    },
    {
      "id": "07afe142-5371-4847-b77b-8adeeec7a7e1",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        864,
        -144
      ],
      "parameters": {
        "color": 4,
        "width": 512,
        "height": 496,
        "content": "## Lead Qualifier on Predefined rules"
      },
      "typeVersion": 1
    },
    {
      "id": "37cd7a08-2210-46c8-96ba-93ff6d00de4f",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1456,
        -80
      ],
      "parameters": {
        "color": 3,
        "width": 864,
        "height": 256,
        "content": "## Notifying team and Updating CRM if qualified"
      },
      "typeVersion": 1
    },
    {
      "id": "2013ca8d-0ba3-4a2d-ac58-b37e0b036487",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1504,
        240
      ],
      "parameters": {
        "color": 2,
        "width": 896,
        "height": 240,
        "content": "## Only updating CRM if not qualified"
      },
      "typeVersion": 1
    },
    {
      "id": "0434cf01-3518-47b2-b520-f013d63c5a6d",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -784,
        80
      ],
      "parameters": {
        "width": 704,
        "height": 592,
        "content": "### \ud83d\ude80 AI Lead Enricher & Qualifier using Bright Data MCP and Hubspot( By Sparsh from Automation Jinn automationjinn.com)\n\nThis workflow converts **raw form submissions \u2192 enriched CRM profiles \u2192 qualified lead alerts** with zero manual effort.\n\n#### \ud83d\udd01 Flow Summary\n1. **Form Trigger** captures Name + Email.\n2. **AI Lead Enricher Agent** (Azure OpenAI + Bright Data MCP) enriches missing fields:\n   - Job title  \n   - LinkedIn profile  \n   - Country  \n   - Company info (name, industry, size, HQ, funding, revenue, etc.)\n3. **Lead Scoring Agent** generates a single **Fit Score (0\u2013100)** based on ICP alignment.\n4. **Routing Logic**\n   - **Fit Score > 70 \u2192 Sales-qualified**\n     - HubSpot contact + company updated  \n     - Slack notification sent to team\n   - **Fit Score \u2264 70 \u2192 Not qualified**\n     - HubSpot updated silently (no Slack)\n\n#### \ud83c\udfaf Goal\nEnsure **only high-quality leads reach the sales team** while maintaining a **clean and consistently enriched CRM** \u2014 automatically.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "75bd64e6-ad70-4f52-aa29-cab59057dc33",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        -144
      ],
      "parameters": {
        "color": 6,
        "height": 208,
        "content": "## Form Trigger"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "c7553f5d-0eb8-4b14-aea6-294c5d15898d",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Create or update a contact",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create or update a contact1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MCP Client": {
      "ai_tool": [
        [
          {
            "node": "Lead Enricher Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update a company2": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Scoring Agent": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Lead Enricher Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Enricher Agent": {
      "main": [
        [
          {
            "node": "Lead Scoring Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Azure OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Lead Enricher Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Azure OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Lead Scoring Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Lead Enricher Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser1": {
      "ai_outputParser": [
        [
          {
            "node": "Lead Scoring Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Create or update a contact": {
      "main": [
        [
          {
            "node": "Search for a company by Domain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create or update a contact1": {
      "main": [
        [
          {
            "node": "Search for a company by Domain1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search for a company by Domain": {
      "main": [
        [
          {
            "node": "Update a company2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search for a company by Domain1": {
      "main": [
        [
          {
            "node": "Update a company",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}