# n8n Inbox Triage with LLM Classification

> Classify incoming email into categories with structured output, then label, route, or draft replies.

Category: n8n Automation Blueprints  
Tags: n8n, email, classification, gmail  
Setup time (estimate): 1-2 hours  
Estimated cost: n8n self-hosted is free (n8n Cloud is paid); one small LLM call per email.  
Last verified: not yet independently verified

## Nodes

1. **Gmail Trigger** (poll every minute) or **Email Trigger (IMAP)**.
2. **Basic LLM Chain** with a **Structured Output Parser** using the schema below.
3. **Switch** on `category`.
4. Branches: add Gmail label, forward to a teammate, create a task, or **Gmail → Create Draft** for `needs_reply`.

## Output schema

```json
{
  "type": "object",
  "properties": {
    "category": {"type": "string", "enum": ["needs_reply", "fyi", "invoice", "newsletter", "spam_like"]},
    "urgency": {"type": "string", "enum": ["low", "normal", "high"]},
    "summary": {"type": "string"}
  },
  "required": ["category", "urgency", "summary"]
}
```

## Prompt

```text
Classify this email. Use only the defined categories.
From: {{ $json.from }}
Subject: {{ $json.subject }}
Body (truncated): {{ $json.text.slice(0, 4000) }}
```

Create drafts rather than sending automatically; review them before they go out.

## Failure modes

- Misclassified urgent emails get buried; review low-confidence labels.
- Long threads exceed context; trim quoted history before classifying.
- Email content can carry prompt injection; never let triage take actions on its own.
