# AI scoring and routing (/docs/workflows/ai-routing)

> Let an AI Assistant node score or classify leads, route each group with a Switch, and test a single node.

The **AI Assistant** node reads information and answers. Pair it with a
**Switch** to send each lead down the right path.

![The AI Lead Scoring and Smart Routing template](/docs-images/workflows/template-ai-scoring.jpg)

The *AI Lead Scoring and Smart Routing* template: a lead arrives, the **AI
Scoring Engine** (1) scores it, the **Switch** (2) routes it, and each group
goes to its own campaign, email, or ticket (3). Yellow boxes are Notes left by
the template author.

## Set up the AI node [#set-up-the-ai-node]

![AI Assistant settings](/docs-images/workflows/ai-assistant-settings.jpg)

| Setting | What it does |
|---|---|
| Model | Which AI model answers. |
| Web search | Lets the AI look things up online. |
| System prompt | Who the AI is and the rules it follows, for example a scoring rubric: +30 for urgency, +20 for referrals, -20 for incomplete profiles. Up to 4,000 characters. |
| User prompt | The task, with lead details inserted using `@`. Up to 4,000 characters. |
| Temperature | Lower gives more consistent answers, higher more creative ones. Keep it low for scoring and routing. |
| Max tokens | Maximum answer length. |
| Output | **Text**, or **JSON** with named **Response fields** such as `score`, `tag`, and `reason`. Each field becomes its own variable that later nodes can check. |

## Route with a Switch [#route-with-a-switch]

A **Switch** checks its cases from top to bottom. The first case that matches
wins. Anything that matches no case goes to **Else**.

![Switch cases](/docs-images/workflows/switch-cases.jpg)

1. Cases run in order.
2. **Add Case**.
3. Each case is one rule, here "score is 70 or more, go to Priority / Hot".

Text matches are exact: "HOT" is not "hot". Tell the AI exactly which words
to answer with, put the most specific case first, and always connect
**Else** (for example to a team alert) so unexpected answers aren't dropped.

## Test a single node [#test-a-single-node]

The flask icon in a node's settings opens **Test node**. It runs only that
node with its current on-screen settings (no save needed), using sample
values you type in place of earlier nodes.

![Testing a single AI node](/docs-images/workflows/test-single-step.jpg)

1. Fill in sample values.
2. Read the **Outcome**.
3. **Run node**.

With the sample left empty, the AI scored this lead COLD (-20) for an
incomplete profile. With a referral lead who wrote "need a solution this
month, budget approved", it scored HOT (75).

This is the fastest way to tune prompts, API requests, and messages. Like a
full test it is real: an email node really sends.