Lead routing rules
@revopslab/lead-routing-rules
Design, test, and apply lead routing rules outside your CRM. Write ordered rules in a JSON file (existing-account match, partner, segment, region, junk filters), prove them with rule tests, then route a leads CSV with weighted round robin, out-of-office skips, and a fallback queue. Works with HubSpot, Salesforce, or any CSV.
- Activity
- New: be the first to try it
- Installs
- 0 installs
- Likes
- 0 likes
- Clones
- 0 clones
What it makes
Real output from this kit
- Sample file565 bytes, download to openRouted summaryFrom the kit's tests
- Sample file1 KB, download to openRoutedFrom the kit's tests
- Sample file554 bytes, download to openRouted 2 summaryFrom the kit's tests
How this works
- It is a skill: written instructions Claude reads when your request matches what the skill is for. You do not call it by name; just ask for the task.
- While it works, it reads and changes files in the places it lists, nowhere else.
- It runs these commands on your computer: node scripts/route.mjs.
- Nothing runs until you choose to use it, and you can remove it any time.
SKILL.md
Lead routing rules
Routing logic usually lives in a CRM workflow nobody can read. This kit keeps it in one small JSON file with tests, so you can see every rule, prove it works on sample leads, and route a list the same way every time.
When to use
- Designing or changing routing (new segment, new rep, new region).
- Routing a one-off list (event, webinar, purchased list) before import.
- Debugging: "why did this lead go to X?" Run the lead through the rules and read the
rule_idandreason. - Not for scoring leads, and not for writing into the CRM. Import the routed CSV yourself, or rebuild the tested rules in your CRM's workflow tool.
Inputs
- Rules at
data/routing-rules.json(start from the kit'sexamples/routing-rules.json). - Leads CSV at
data/leads.csv. Any columns; rules refer to them by name, lowercased with spaces as underscores (Lead Sourcebecomeslead_source). - Accounts CSV (optional) with a domain or website column and an owner column, for existing-account matching.
Rules file
rules: checked in order, the first match wins. Each hasid,when(all must match) and orwhen_any(one must match),assign(owner,pool, orqueue), and areason.- Ops:
==,!=,in,not_in,>,>=,<,<=,contains,starts_with,ends_with,exists,missing. Text compares ignore case. Numbers use the first number in the cell, so201-500employees counts as 201. - Built-in fields:
email_domain,is_free_email(common personal email providers),company_domain. pools: round robin groups with optionalweights("Rep C": 2gets twice the leads).out_of_office: people to skip.- Existing accounts are checked before all rules when
--accountsis given (skip with"account_match": false). Personal emails never match an account. fallback: where unmatched leads go. Default queueunassigned.tests: sample leads withexpect_ruleand optionalexpect_to(owner, pool name, or queue).
Steps
- Design. Ask for the routing policy in plain words, then write the rules file. Put specific rules (junk, existing accounts, partners) before broad ones (segments). Write one test per rule plus edge cases (missing size, personal email, employee ranges).
Test.
node scripts/route.mjs data/routing-rules.json --checkEvery test must pass. If one fails, show expected vs actual and fix the rule, not the test, unless the user agrees the test was wrong.
Route.
node scripts/route.mjs data/routing-rules.json data/leads.csv --accounts data/accounts.csv --state data/rr-state.json --out out --name routedRouting refuses to run while any rule test fails.
--statekeeps the round robin position between runs so the next list continues where this one stopped.- Report from
out/routed-summary.json: leads per rule, per person, how many hit the fallback, andunused_rules. A rule nobody hit may be dead or ordered too late.
Output to the user
Routed 10 leads. 5/5 rule tests pass.
| Rule | Leads |
| --- | ---: |
| existing-account | 2 |
| enterprise | 2 |
| smb | 2 |
| fallback | 1 |
Per person: Rep A 2, Rep F 2, Rep B 1, Rep C 1, Rep E 1, Partner Manager 1.
1 lead hit the fallback (UnknownCo: no employee count). Unused rule: spam-or-test.
File to import: out/routed.csv (adds routed_to, route_type, rule_id, reason).Guardrails
- Never import or assign in the CRM. The user imports
out/routed.csv. - Keep a test for every rule you add. Do not delete a failing test to make routing run.
- Do not route on protected or sensitive attributes (age, gender, ethnicity, religion, and similar), even if a column exists.
- Lead data is personal data. Summarize in chat; do not paste the CSV.
README.md
Lead routing rules
Keeps your lead routing in one readable rules file, with tests that prove each rule works, and routes any leads CSV the same way every time. Weighted round robin, out-of-office skips, existing-account matching, and a fallback queue are built in.
Who it is for
RevOps and marketing ops teams designing or debugging routing, and anyone routing a list from an event before importing it into HubSpot, Salesforce, or another CRM.
Example
Input: examples/routing-rules.json (junk filter, personal email to nurture, partner leads, enterprise, mid-market, and SMB pools, one rep out of office), examples/leads.csv (10 leads), and examples/accounts.csv.
Output: out/routed.csv with four new columns, for example:
buyer@northwind.example,...,Rep A,owner,existing-account,existing account northwind.example
cto@fabrikam.example,...,Rep A,pool,enterprise,"1,000+ employees"
someone@gmail.com,...,nurture,queue,free-email-students,Personal email and no company size
new@unknownco.example,...,routing-review,queue,fallback,no rule matchedAnd out/routed-summary.json: counts per rule and per person, rules nobody hit, and test results (5/5 pass).
What it can access
- Runs
node scripts/route.mjs(Node built-ins only, no network). - Reads
data/(plus the kit's ownexamples/), writesdata/(round robin state) andout/.
Setup
None. Copy examples/routing-rules.json to data/ and edit it, or ask Claude to write it from your routing policy.
Files
- README.md
- SKILL.md
- examples/accounts.csv
- examples/leads.csv
- examples/routing-rules.json
- kit.json
- scripts/route.mjs
Did it work?
0worked for them0did not work
Sign in to say whether it worked for you.
Nobody has said yet. Tried it? Tell the next person.
