# AI lead routing n8n template

> This n8n template takes a form submission by webhook, checks HubSpot for an existing contact or account owner, has Claude label the message by intent, product line and urgency, and applies territory, segment and weighted round-robin rules from a Google Sheet to set the HubSpot owner. Reps get a Slack alert, every decision is logged, and leads untouched after an hour are escalated. You need HubSpot, Google Sheets, Anthropic and Slack credentials.

- Platform: n8n
- Download: https://www.lumeor.studio/templates/n8n/ai-lead-routing.json
- Trigger: Webhook from your website form, plus a 30 minute SLA schedule
- Credentials needed: HubSpot Service Key, Google Sheets OAuth2, Anthropic API, Slack
- Full guide: https://www.lumeor.studio/guides/ai-lead-routing/
- Last updated: 2026-10-14

## What this workflow does

1. **New inquiry** receives the form submission as JSON on a webhook.
2. **Normalize lead** maps common field names (email, company, state, employees, message), lowercases the email and rejects submissions without a valid address.
3. **Find existing contact** searches HubSpot by exact email, and by company domain for non-free email providers.
4. **Classify inquiry** sends the message to Claude, which returns intent, product line, urgency, a one-line summary and a reason. It uses structured outputs with low effort.
5. **Read routing table** loads your rules from Google Sheets.
6. **Apply routing rules** is plain JavaScript. Spam is logged only. Support requests, partnerships, vendor pitches and job seekers go to the right queue. Existing contacts and accounts stay with their owner. Everything else gets the matching rule with the lowest priority number, then weighted round-robin with daily caps. Gaps fall back to a default owner and alert sales ops.
7. **Log routing decision** appends a row to the `Routing log` tab.
8. **Route** sends sales leads to **Assign owner in HubSpot** (create or update the contact with its owner), and both sales and non-sales items to **Notify rep or queue** in Slack.
9. **Every 30 min SLA check** runs on weekdays from 8am to 6:30pm, finds leads assigned one to four hours ago with no logged contact, and **Format SLA misses** sends each one to the alert channel.
10. Errors, refusals and table problems go to **Alert: routing needs attention**.

## Before you import

- A current n8n version with a public URL for the production webhook.
- A HubSpot private app token with contact read and write scopes.
- A Google Sheet for the routing table and log.
- An Anthropic API key and a Slack app that can post to your channels.

## Setup

1. Import the JSON, then build the `Routing` and `Routing log` tabs from the layout in the yellow note.
2. Attach credentials: Google Sheets OAuth2 on both sheet nodes, HubSpot Service Key on the two HubSpot search nodes and the HubSpot node, Anthropic on **Classify inquiry**, Slack on both Slack nodes.
3. Replace `REPLACE_WITH_ROUTING_SHEET_ID` (two nodes) with your sheet ID.
4. In **Apply routing rules**, replace `REPLACE_WITH_DEFAULT_OWNER_ID` with a HubSpot owner ID.
5. Replace `REPLACE_WITH_SALES_CHANNEL`, `REPLACE_WITH_OPS_CHANNEL` and `REPLACE_WITH_ALERTS_CHANNEL`.
6. Edit the `product_line` values in the Claude schema to match your catalog, and use the same values in the sheet.
7. If your form sends nested data (Typeform does), adjust the field mapping in **Normalize lead**.

## Test it

Activate the workflow, then POST a sample lead to the production URL with curl, for example an email, company, state `PA`, `employees` of 120 and a message asking for pricing. Check that the contact appears in HubSpot with the expected owner, the rep is tagged in Slack and a row lands in the log. Repeat with a job application message and confirm it goes to the ops channel with no owner. Round-robin counters only persist in active executions, so test rotation with the workflow switched on.

## Make it production-ready

- **Deduplicate.** Ignore repeat submissions from the same email within a short window before assigning.
- **Secure the webhook.** Turn on header authentication in the Webhook node and send the secret from your form.
- **Error workflow.** Add an n8n error workflow so failures outside the alert path still reach someone.
- **Business-hours SLAs.** Adjust the SLA query so overnight leads are measured from the next business morning.
- **Rate limits.** HubSpot limits requests per private app, so keep retries on and avoid bulk replays through the webhook.
- **Review misroutes.** Check the log weekly and fix the sheet, not the prompt.

The [AI lead routing guide](/guides/ai-lead-routing/) covers routing design, enrichment timing and what breaks in production. For a hand with your routing rules, [get in touch](/start/).

---

Source: https://www.lumeor.studio/templates/ai-lead-routing/
Published by Lumeor Studio, Newtown, PA. hello@lumeor.studio. Get a written scope: https://www.lumeor.studio/start/
