# Text Classifier and Smart Routing — AI Automation with n8n

Source: https://www.geekswithgeeks.com/en/n8n-ai-automation/ai-classifier-routing

> Classify incoming text and send each item to the right branch.

## AI as a router

The **Text Classifier** node takes text and a list of categories (each with a short description) and sends the item down the output for the best match. This replaces long chains of keyword rules for messy input such as support emails. Provide a clear "other" category so unclear items go to a person.

## Rules vs AI routing

This keyword router ran in Node.js and routes three test messages correctly. It is cheap and predictable but brittle: "my card was charged twice" would fall through to general. AI classification handles such phrasing but costs tokens.

```javascript
const route = t =>
  /refund|money back/i.test(t) ? "billing" :
  /error|crash|bug/i.test(t)   ? "technical" : "general";

console.log(["I want a refund", "App crash on login", "Hello"].map(route).join(","));
```

Output:

```
billing,technical,general
```

## Use rules first, AI second

Cheap deterministic checks (sender domain, a known ID format) can handle obvious cases for free. Send only the remaining ambiguous items to the classifier to save cost.

**Quiz:** Why include an "other" category in a text classifier?

- [ ] It hides errors
- [ ] It speeds up the model
- [ ] It is required by the licence
- [x] So unclear items can be sent to a person instead of being forced into a wrong category

*Answer:* So unclear items can be sent to a person instead of being forced into a wrong category. A safe default prevents confident but wrong routing of odd inputs.
