Inspectable workflow example

AI Email Router with n8n

A practical n8n workflow that reads Gmail, normalizes the fields, adds basic rule signals, classifies the email with Groq, validates the result, routes a lead into a CRM sheet, alerts Slack, and logs the operation.

AI Email Router cover with a Gmail to routing workflow concept

This is a demo workflow, not a fake client case study. The goal is to show the useful parts of AI automation in the Philippines: the input, the rules, the classifier, the validation step, the route, and the log.

The lead path is walked through in detail because it is enough to show the pattern. Support, invoice, spam, and review branches use the same structure: validate first, route second, act third, log last.

The slow part is not connecting nodes.

It is deciding what should happen, testing real emails, tuning labels, and making the workflow understandable enough for someone else to own.

Trigger Unread Gmail message
AI step Groq classifier returns JSON
Detailed path Lead -> CRM -> Slack -> log

The full workflow map

The canvas has five possible routes. This page follows the lead route end to end, while keeping the other branches visible on the map.

n8n workflow canvas for an AI Email Router
The workflow uses rules, AI classification, validation, routing, action nodes, and one master Google Sheets log.

1. Start with a controlled test email

Before building the rest of the workflow, send yourself one test email for the scenario you want to prove. In this case, the test email is a lead inquiry asking about n8n automation services and pricing.

The Gmail Trigger is then tested and pinned. That gives every next node a stable input while the workflow is being built, instead of waiting for Gmail to trigger again.

Gmail Trigger node with pinned test event data
The first checkpoint is simple: confirm that Gmail exposes the message id, subject, sender, snippet, labels, and payload.

2. Normalize fields once

Gmail gives useful data, but it is not shaped for the rest of the workflow. The Extract Fields node turns raw Gmail output into clean top-level fields: sender, sender name, domain, subject, body snippet, attachment names, MIME types, and a PDF flag.

Extract Fields n8n code node
Normalize once, then every later node can use clean expressions like sender, domain, subject, and has_pdf.

3. Add basic rule signals before AI

Basic Rules does not replace the classifier in this demo. It adds cheap, inspectable signals before the AI step: suspicious domains, no-reply senders, newsletter patterns, aggressive spam words, trusted domains, and attachment flags.

That makes the workflow easier to review. If the model later calls something spam, validation can check whether the rule-based signals agree before archiving anything.

Basic Rules n8n code node with spam and marketing signals
The rules are intentionally editable. A real team would tune known spam domains, newsletter senders, and trusted domains over time.

4. Keep the AI classifier small

The classifier is called through an HTTP Request to Groq. Its job is narrow: return one label, one confidence score, and one short reason.

{
  "label": "lead",
  "confidence": 0.95,
  "reason": "The email is an inquiry about services and pricing from a potential client."
}
AI Classifier HTTP Request node for Groq
The AI does not create tickets, archive email, or decide the final business action. It only returns structured classification data.

5. Validate before routing

AI output is not safe to trust directly. It can return markdown, broken JSON, a low confidence value, or a label that is semantically correct but operationally unsafe.

1

Invalid JSON goes to review. The workflow should not fall over because the model wrapped JSON in markdown.

2

Confidence below 0.75 goes to review. If the model is unsure, a human should see it.

3

Spam needs rule confirmation. A spam label alone is not enough to archive a message.

4

Invoice without PDF goes to review. The action depends on attachments, not only on the AI label.

6. Route by validated route, not raw AI label

The router uses the validated route field. This keeps the Switch node simple: the safety decisions already happened in Validation.

Routing Rules switch node in n8n
Routes include support, lead, invoice, spam archive, and human review.

7. Lead path: CRM, Slack, and master log

The tested path for this demo is lead routing. The workflow writes a CRM row, posts a Slack alert, and then appends the operation to the master log.

Add to CRM Google Sheets node
Google Sheets receives the sender name, email, domain, subject, source, status, and created timestamp.
Slack message for a new lead
Slack gets a readable lead alert with the classification reason and confidence.
CRM Leads Google Sheet after the workflow runs
The CRM sheet is intentionally plain. For many small workflows, a clean table is enough for the first version.
Email Router Log Google Sheet after the workflow runs
The master log records completed routes: message id, timestamp, sender, label, confidence, reason, route, and action.
Master Log Google Sheets node in n8n
This demo log records completed workflow routes. A production version should add a separate Error Trigger workflow for failed executions.

Other branches use the same pattern

Fully testing every branch means preparing separate tables, statuses, dates, files, review rows, and sometimes real attachments. That setup work matters more than simply drawing lines between nodes.

support

Create a Notion or Airtable ticket, draft a reply, notify Slack, then log the completed route.

invoice

Save the PDF to Drive, add a row to an invoice sheet, notify admin, then log the route. If there is no PDF, send it to review.

spam

Archive only when rule signals and confidence agree. Otherwise send it to review.

review

Add uncertain messages to a human review queue instead of forcing the workflow to guess.

What this demo does not cover

This is a useful first version, not the final production checklist. A production build would add an Error Trigger workflow, retry rules, stricter credential ownership, more test messages, and clearer handoff notes for the person who owns the inbox.

It would also test each branch with real examples: a support question, a real invoice PDF, a marketing email, a spam candidate, and at least one messy message that should go to review.

The setup pieces can be scaffolded too, such as a Drive folder, Sheets logs, a CRM sheet, and a Notion ticket database. I covered that pattern in the Claude connectors guide.

Bottom line

This is the kind of workflow automation Philippines teams can inspect: one trigger, clean fields, editable rules, a small AI classifier, validation before action, visible branches, Slack alerts, and a master log.

It is not AI magic. It is a small operations workflow that becomes useful when the labels, thresholds, and ownership are tuned against real email.

Want to map one inbox workflow?

Send the inbox type, the first labels that matter, and where each route should go. I will map the smallest useful version first.

Map my inbox