# Lead routing, with a review queue

An offline starter kit from Cut the SaaS. It helps you write and test a routing policy before connecting it to a form, CRM or automation platform.

This is a local Node.js program, not a Make, n8n or TinyCommand import. It makes no network requests, sends no messages and changes no CRM records. It is not a production lead-management service.

## Run the sample

Use Node.js 20 or later. Unzip the kit, open a terminal in its folder, then run:

```sh
node verify.mjs
node route-leads.mjs sample-leads.json rules.json
```

The first command checks the 24 fictional enquiries against their expected decisions. The second prints the decisions as JSON. It does not write an output file or modify the input.

To try the deliberately simple keyword baseline:

```sh
node route-leads.mjs sample-leads.json rules.json --keywords
```

All sample enquiries are fictional. There are no real names, email addresses or customer records in this package.

## The routing policy

1. An enquiry needs a stable ID and a non-empty message. Invalid entries go to Human review.
2. If an ID appears more than once in the batch, every copy goes to Human review. The runner does not silently discard or choose a duplicate.
3. Declared support requests go to Support team. Declared billing requests go to Billing team.
4. Sales requests need a valid whole-number team size. Fewer than 100 employees goes to Founder sales; 100 or more goes to Account team.
5. Missing, unknown or invalid information goes to Human review. That queue is an output in this example: a real person is not automatically notified.

The employee threshold and queue names in `rules.json` are editable sample business choices, not recommended defaults for every company. `requestType` must be `sales`, `support` or `billing`; other values require review. The declared request type takes precedence over words in the message. It can still be wrong: this kit does not understand intent or detect dishonest answers.

## Input and output

Input is a JSON array with at most 1,000 records and a file size of at most 1 MiB. Each record uses:

- `id`: 1–64 letters, digits, hyphens or underscores.
- `requestType`: the declared request category.
- `message`: 1–2,000 characters with at least one non-space character.
- `employees`: required only for sales; an integer from 1 to 1,000,000. A numeric string is deliberately reviewed rather than silently converted.

The rules file is also limited to 1 MiB. An invalid file, invalid rules or an oversized batch stops the command with a non-zero exit code. A bad individual record remains in the result as a review item.

Output includes `id`, `status`, `owner` and `reason`, in input order. A missing or invalid ID is reported as null. Input messages are not copied to the output. Keep an appropriate source record in your own system when implementing a review queue.

## What the experiment establishes

`experiment-results.json` compares two local approaches on these same 24 examples:

- Keyword baseline: searches the message for billing words, then support words, then sales words.
- Ordered rules: uses structured request type, team size, validation and duplicate review.

The expected decisions were authored for the policy above. This is an acceptance example, not a random sample, independent benchmark or estimate of real-world accuracy. The structured approach receives information the keyword approach ignores. The comparison demonstrates the value and trade-offs of collecting explicit inputs; it does not isolate algorithm quality.

No AI model or vendor service is tested. The results establish neither better conversion nor faster response times. Real intake data can be ambiguous, incomplete or misleading in ways these examples do not cover.

## Before connecting real systems

- Agree queue ownership and make sure someone works the review queue.
- Test your actual form fields, permissions and provider behavior in a sandbox.
- Persist event IDs across runs. This example detects duplicates only inside one batch; it does not provide persistent idempotency.
- Decide what to do when a declared request category conflicts with the message.
- Add delivery retries, failure alerts and an audit trail before assigning or sending anything externally.
- Limit access to personal data, keep only what you need, and never place credentials in a downloaded rules file.
- Measure real results before making claims about sales, costs or time saved.

Test record: November 20, 2026. Re-run `node verify.mjs` after changing the routing policy and update the expected decisions deliberately.

Read the accompanying recipe: https://cut-the-saas.com/go-to-market/inbound-lead-capture

Kit page: https://cut-the-saas.com/workflow-kits/lead-routing
