This workflow corresponds to n8n.io template #11832 — we link there as the canonical source.
This workflow follows the Gmail → Gmail Trigger recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"id": "1Y3MxcSnIXg7UELD",
"meta": {
"templateCredsSetupCompleted": true
},
"name": "Smart sales lead routing with sentiment analysis",
"tags": [],
"nodes": [
{
"id": "e37e32ee-7b47-4289-ac58-5e3bb0ad4c4c",
"name": "Sentiment Analysis",
"type": "@n8n/n8n-nodes-langchain.sentimentAnalysis",
"position": [
144,
-64
],
"parameters": {
"options": {
"categories": "Positive, Neutral, Negative",
"enableAutoFixing": false,
"systemPromptTemplate": "You are highly intelligent and accurate sentiment analyzer. Analyze the sentiment of the provided text. Categorize it into one of the following: {categories}. Use the provided formatting instructions.\nEvaluate if the categorization correctly identifies the user's intent towards OUR company. Ignore negative sentiment directed at third parties/competitors. The user is angry at a competitor, but wants to buy our product. Correct label is 'High-Value Lead'.\nYOU MUST CHOOSE EXACTLY ONE CATEGORY!",
"includeDetailedResults": true
},
"inputText": "={{ $json.text || $json.input }}"
},
"executeOnce": true,
"retryOnFail": true,
"typeVersion": 1.1,
"alwaysOutputData": false
},
{
"id": "63d29c05-8053-47df-8e7c-1cb88a7bce92",
"name": "Send Hot Lead Email",
"type": "n8n-nodes-base.gmail",
"position": [
960,
-208
],
"parameters": {
"sendTo": "user@example.com",
"message": "={{ $('Gmail Trigger').item.json.text }}",
"options": {},
"subject": "Hot Lead!"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "6d6ec96a-f50a-46ca-94ad-716d8e0161ed",
"name": "Gmail Trigger",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-256,
144
],
"parameters": {
"simple": false,
"filters": {},
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "d1f138bb-c5a6-48c9-a3af-9a26ee99e6bf",
"name": "Send Marketing Insights Email",
"type": "n8n-nodes-base.gmail",
"position": [
960,
224
],
"parameters": {
"sendTo": "user@example.com",
"message": "={{ $('Gmail Trigger').item.json.text }}",
"options": {},
"subject": "Sales insights"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "5f4cbf8a-5c46-48fa-a954-2eaf1654ef1e",
"name": "Send Follow-up Notification",
"type": "n8n-nodes-base.gmail",
"position": [
960,
16
],
"parameters": {
"sendTo": "user@example.com",
"message": "={{ $('Gmail Trigger').item.json.text }}",
"options": {},
"subject": "Follow-up"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "26d746f3-7c0b-4be9-843c-f10fe966aa9d",
"name": "When fetching a dataset row",
"type": "n8n-nodes-base.evaluationTrigger",
"onError": "continueRegularOutput",
"position": [
-768,
-128
],
"parameters": {
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "LHUrQaGzxlnqJGRW",
"cachedResultUrl": "/projects/UW9P2Zs3ONybpK7q/datatables/LHUrQaGzxlnqJGRW",
"cachedResultName": "Sentiment Analysis Evaluation"
}
},
"typeVersion": 4.7
},
{
"id": "57569de6-9c6a-45c5-9bc1-658de92de598",
"name": "Loop Over Items",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-384,
-128
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "c11fd81a-3557-4603-8a5a-5d09b5bd49d9",
"name": "Google Gemini 3 PRO",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
304,
272
],
"parameters": {
"options": {},
"modelName": "models/gemini-3-pro-preview"
},
"credentials": {
"googlePalmApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "37f06ddd-b216-43b2-b74f-878082f1ecac",
"name": "Google Gemini 2.5 Flash Lite",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
-16,
272
],
"parameters": {
"options": {},
"modelName": "models/gemini-2.5-flash-lite"
},
"credentials": {
"googlePalmApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "b1b8e314-d90e-4f8d-b169-a952705af643",
"name": "Google Gemini 2.5 Flash",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
144,
272
],
"parameters": {
"options": {}
},
"credentials": {
"googlePalmApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "2e185551-f4ca-4765-93b3-dab08b5a1f47",
"name": "Set Metrics",
"type": "n8n-nodes-base.evaluation",
"position": [
1232,
-416
],
"parameters": {
"metric": "categorization",
"options": {},
"operation": "setMetrics",
"actualAnswer": "={{ $json.sentimentAnalysis.category }}",
"expectedAnswer": "={{ $json.expected }}"
},
"typeVersion": 4.8
},
{
"id": "18cb4cec-51b9-4ad1-97ea-4cd26590145e",
"name": "Save Output",
"type": "n8n-nodes-base.evaluation",
"position": [
960,
-416
],
"parameters": {
"outputs": {
"values": [
{
"outputName": "result",
"outputValue": "={{ $('Sentiment Analysis').item.json.sentimentAnalysis.category }}"
}
]
},
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "LHUrQaGzxlnqJGRW",
"cachedResultUrl": "/projects/UW9P2Zs3ONybpK7q/datatables/LHUrQaGzxlnqJGRW",
"cachedResultName": "Sentiment Analysis Evaluation"
}
},
"typeVersion": 4.8
},
{
"id": "348109ae-f348-4be6-bf5b-91a597f71c4c",
"name": "Check Neutral",
"type": "n8n-nodes-base.evaluation",
"position": [
624,
32
],
"parameters": {
"operation": "checkIfEvaluating"
},
"typeVersion": 4.8
},
{
"id": "ffd80461-ca7d-4056-9096-9c752fd6412c",
"name": "Check Positive",
"type": "n8n-nodes-base.evaluation",
"position": [
624,
-176
],
"parameters": {
"operation": "checkIfEvaluating"
},
"typeVersion": 4.8
},
{
"id": "d72b7a4b-ffe1-4d3b-a4f8-3045c22834ed",
"name": "Check Negative",
"type": "n8n-nodes-base.evaluation",
"position": [
624,
224
],
"parameters": {
"operation": "checkIfEvaluating"
},
"typeVersion": 4.8
},
{
"id": "f43ec853-0699-4356-9c4a-caf4f6246b73",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-864,
-224
],
"parameters": {
"color": 7,
"width": 336,
"height": 304,
"content": "## EVALUATION TRIGGER"
},
"typeVersion": 1
},
{
"id": "f376c030-19f8-4c86-94a5-f04287d2d1e7",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
512,
-368
],
"parameters": {
"color": 7,
"width": 336,
"height": 768,
"content": "## SAFETY GATE"
},
"typeVersion": 1
},
{
"id": "d1e95df2-73b0-492d-b382-2ddf669f6d8c",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
880,
-480
],
"parameters": {
"color": 7,
"width": 528,
"height": 208,
"content": "## METRIC RECORDING AND EVALUATION"
},
"typeVersion": 1
},
{
"id": "fddf540c-0b59-4cb3-bbe5-30fedcbd8020",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
96,
-192
],
"parameters": {
"color": 7,
"width": 352,
"height": 384,
"content": "## CORE LOGIC"
},
"typeVersion": 1
},
{
"id": "bf894ea2-ab27-4a74-9b00-7dfa8742166c",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1552,
-416
],
"parameters": {
"width": 592,
"height": 816,
"content": "# Smart Sales Lead Routing with Evaluation Framework\n\nThis workflow automates the categorization and routing of sales leads while providing a built-in sandbox for model evaluation. It uses Google Gemini to analyze the sentiment of incoming emails and routes them based on their business value.\n\n## How it works\n\n* Production Path: The Gmail Trigger ingests new emails, which are sent to the Sentiment Analysis node. Based on the result, leads are routed to specific Gmail notification nodes.\n* Evaluation Path: The Evaluation Trigger pulls a \"Golden Dataset\" from an n8n Data Table. The Evaluation nodes then compare the AI's actual output against your ground-truth labels to calculate accuracy.\n* The Safety Gate: \"Check if Evaluating\" nodes ensure that during a test run, the workflow follows the evaluation logic and never sends actual emails to the sales team.\n\n## How to use\n\n* Configure Credentials: Set up your Gmail OAuth2 and Google Gemini API credentials.\n* Prepare Data: Create an n8n Data Table with columns for input text and an expected sentiment label.\n* Test Models: Connect different Gemini model nodes (Flash Lite, Flash, or Pro) to the Sentiment Analysis node to compare latency and accuracy.\n\nAnalyze Results: Run the Evaluation Trigger to populate the Data Table with success metrics."
},
"typeVersion": 1
}
],
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "d471419c-0262-4203-b15a-1677050969f6",
"connections": {
"Save Output": {
"main": [
[
{
"node": "Set Metrics",
"type": "main",
"index": 0
}
]
]
},
"Set Metrics": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Check Neutral": {
"main": [
[
{
"node": "Save Output",
"type": "main",
"index": 0
}
],
[
{
"node": "Send Follow-up Notification",
"type": "main",
"index": 0
}
]
]
},
"Gmail Trigger": {
"main": [
[
{
"node": "Sentiment Analysis",
"type": "main",
"index": 0
}
]
]
},
"Check Negative": {
"main": [
[
{
"node": "Save Output",
"type": "main",
"index": 0
}
],
[
{
"node": "Send Marketing Insights Email",
"type": "main",
"index": 0
}
]
]
},
"Check Positive": {
"main": [
[
{
"node": "Save Output",
"type": "main",
"index": 0
}
],
[
{
"node": "Send Hot Lead Email",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[],
[
{
"node": "Sentiment Analysis",
"type": "main",
"index": 0
}
]
]
},
"Sentiment Analysis": {
"main": [
[
{
"node": "Check Positive",
"type": "main",
"index": 0
}
],
[
{
"node": "Check Neutral",
"type": "main",
"index": 0
}
],
[
{
"node": "Check Negative",
"type": "main",
"index": 0
}
]
]
},
"Google Gemini 3 PRO": {
"ai_languageModel": [
[]
]
},
"Google Gemini 2.5 Flash": {
"ai_languageModel": [
[]
]
},
"When fetching a dataset row": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Google Gemini 2.5 Flash Lite": {
"ai_languageModel": [
[
{
"node": "Sentiment Analysis",
"type": "ai_languageModel",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
gmailOAuth2googlePalmApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
This n8n template demonstrates how to deploy an AI workflow in production while simultaneously running a robust, data-driven Evaluation Framework to ensure quality and optimize costs.
Source: https://n8n.io/workflows/11832/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
This template and YouTube video goes over 5 different implementations of evaluations within n8n. Categorization Correctness Tools used String similarity Helpfulness
3277. Uses gmailTrigger, textClassifier, lmChatGoogleGemini, emailSend. Event-driven trigger; 16 nodes.
This n8n workflow is designed to intelligently manage incoming emails and automatically send personalized responses based on the content. It classifies emails using LangChain's Text Classifier, sends
This project presents an intelligent email management system powered by advanced artificial intelligence. It utilizes Google's Gemini 2.0 AI model to automatically categorize incoming emails into quer
Complete AI-powered sales system Automates lead capture, qualification, and follow-up from multiple channels. AI INTELLIGENCE: