Xiaobai
Developer · Builder
Building AI engineering systems, developer tools and long-term digital assets at XBSTACK.
About Xiaobai & XBSTACK →
n8n Gmail Summarizer: Extract Action Items to Google Sheets Step by Step
Build an n8n Gmail summarizer with Gmail Trigger, AI structured extraction, priorities and action items, Message ID deduplication, Google Sheets output, and failure handling.
Build an n8n Gmail summarizer with Gmail Trigger, AI structured extraction, priorities and action items, Message ID deduplication, Google Sheets output, and failure handling.
See the results first: What this workflow does
This n8n workflow periodically checks Gmail for new emails, filters out noise using Gmail search conditions, extracts summaries, action items, and priorities via a model, and finally writes deduplicated entries to Google Sheets based on Message ID.
The complete execution path is as follows:
Gmail Trigger
→ Google Sheets query Message ID
→ IF: YesNoprocess
→ Yes:
→ No: AI extract
→ validate
→ Google Sheets
→:
The minimum viable version requires only four types of nodes:
- Gmail Trigger: Fetches new emails;
- Google Sheets: Queries and writes data;
- AI Chat Model + Structured Output Parser: Extracts structured fields;
- IF: Controls deduplication and failure branches.
Fields Written to Google Sheets
It is recommended to create the following headers first:
| Field | Purpose |
|---|---|
| Date | Email received time |
| From | Sender |
| Subject | Email subject |
| Summary | A summary in three sentences or less |
| Action Items | To-dos extracted from the email |
| Priority | low / medium / high |
| Status | Manually maintained processing status |
| MessageID | Idempotent deduplication key |
MessageID must be retained. Without it, workflow retries or repeated polling can easily result in duplicate rows being written to the spreadsheet.
Step 1: Configure Gmail Trigger
The Gmail Trigger checks for new emails according to your configured Poll Times. The node itself also supports filtering parameters such as Read Status, Search, Sender, Label, and the number of items per poll.
During testing, start with minimal filtering conditions:
is:unread
Once the node confirms it can read the email, gradually add more conditions:
is:unread -category:social -category:promotions -from:noreply
This query serves the following purposes:
- Process only unread emails;
- Exclude the Social category;
- Exclude the Promotions category;
- Exclude common automated notification senders.
Avoid stacking a large number of filter conditions from the start. When a Trigger returns no data, it becomes difficult to determine whether the cause is an authorization failure, incorrect polling settings, or overly restrictive Search conditions that filtered out all emails.
Should Simplify Be Enabled or Disabled?
The Gmail Trigger can return simplified results by default, which include the Message ID, labels, and common email header fields. You can enable Simplify when performing subject classification. However, if you need the full email body, check the output of the current node and disable Simplify or append a Gmail Get Message node as necessary.
Step 2: Use Message ID for Idempotent Deduplication
Every email in Gmail has a unique Message ID. Querying before writing helps avoid the following issues:
- Duplicate writes caused by workflow retries;
- The same email re-entering the flow due to overlapping polling intervals;
- The entire execution restarting after a model node timeout;
- Manual re-execution of historical tasks.
Recommended workflow:
[Gmail Trigger]
→ [Google Sheets: MessageID query]
→ [IF: YesNo]
├─ True → []
└─ False → [AI ] → []
Do not rely on the subject line or sender for IF conditions, as different emails may share the same subject. The unique key must be the Message ID.
Step 3: Ensure the model returns a fixed structure
Instead of simply writing “please return JSON” in the prompt, it is more robust to connect the model node to a Structured Output Parser and define the field schema.
{
"type": "object",
"properties": {
"summary": {
"type": "string",
"description": "Description example"
},
"action_items": {
"type": "array",
"items": { "type": "string" },
"description": "return"
},
"priority": {
"type": "string",
"enum": ["low", "medium", "high"],
"description": "risk"
}
},
"required": ["summary", "action_items", "priority"]
}
Recommended Prompts:
Yesextract., extract.
:
1. summary:,.
2. action_items: extractExecute; return.
3. priority:
- high:,, risk;
- medium: processrisk;
- low:,.
4. date,.
5. output Schema.
Step 4: Validate Fields Before Writing to the Spreadsheet
Even when using structured output, it is recommended to add an IF or Code node for minimal validation before writing.
const item = $input.first().json;
if (typeof item.summary !== 'string') {
throw new Error('summary must be a string');
}
if (!Array.isArray(item.action_items)) {
throw new Error('action_items must be an array');
}
if (!['low', 'medium', 'high'].includes(item.priority)) {
throw new Error('priority is invalid');
}
return item;
Google Sheets field mapping can be used for:
Date =
From =
Subject =
Summary = summary
ActionItems = action_items.join("\n")
Priority = priority
Status = process
MessageID = Gmail Message ID
Step 5: Add Notifications for High-Priority Emails
Tables serve as an archival layer and are not suitable for real-time alerts. You can use a Switch node to route traffic based on priority before writing:
high → → write Sheets
medium → write Sheets →
low → write Sheets
Notification nodes can be swapped out for the team’s actual tools, such as Slack, Discord, WeCom, Feishu, or email. When notifications involve external clients, payments, or production operations, they should serve only as alerts; models must not automatically reply or execute irreversible actions.
Error Workflow: Failures Must Be Detectable
The main workflow must handle at least three categories of errors:
- Gmail authorization expiration;
- Model call timeouts, rate limiting, or output validation failures;
- Google Sheets write timeouts or permission errors.
You can establish a separate Error Workflow:
Error Trigger
→ extract workflow, node, execution URL error
→ writeerror
→
Associate this Error Workflow in the main workflow’s Settings. The alert content should include at least:
- Workflow name;
- Failed node;
- Execution time;
- Error summary;
- Execution link;
- Whether safe retries are allowed.
Troubleshooting Common Issues
Gmail Trigger Returns No Data
Check the following items in order:
- Whether the workflow is activated;
- Whether Google OAuth credentials are still valid;
- Whether Poll Times match expectations;
- Whether Read Status is set to read only unread emails;
- Whether Search, Sender, or Label filters are excluding test emails;
- Whether the current email arrived after the node started listening.
During testing, first remove the Search conditions and keep only one newly sent unread email. Once the execution path is confirmed working, restore the filters.
Model Output Cannot Be Parsed
Prioritize using a Structured Output Parser instead of relying on regex to extract JSON from natural language. If it still fails, log the raw model response and route that specific execution to manual review or a retry branch. Do not write incomplete fields into the spreadsheet.
Duplicate Writes to Google Sheets
Ensure the Lookup happens before the model call and Add Row, and confirm that the query column and the write column use the same Message ID. Subject, time, and sender cannot replace an idempotency key.
Google Sheets Write Timeout
Enable limited retries with backoff for the write node. As data volume increases, avoid writing large numbers of rows concurrently. Aggregate into batches first, or use a database as the primary storage and Sheets as the presentation layer.
SQLite Locks in Self-Hosted n8n
SQLite is suitable for experimentation and low-concurrency environments. As the number of workflows, concurrent executions, and execution history grow, evaluate migrating to PostgreSQL, combined with Queue Mode and Worker isolation for long-running tasks. Back up both the database and N8N_ENCRYPTION_KEY before migration, otherwise existing credentials may become undecryptable.
Privacy and Permission Boundaries
Email bodies may contain customer information, contracts, verification codes, financial data, and internal links. Before going live, implement at least the following restrictions:
- Use dedicated Google credentials, authorizing only the necessary mailboxes;
- Use Search conditions to filter out emails that clearly should not enter the model;
- Do not send attachments to the model by default;
- Set an upper limit on body length;
- Do not save full email bodies in logs;
- Restrict sharing scope when writing to spreadsheets;
- Manual confirmation must be retained for automated replies, forwards, deletions, and payment-related actions.
Final Checklist
- Gmail Trigger can stably retrieve test emails;
- Search conditions do not accidentally filter out emails that need processing;
- Message ID lookup occurs before the model call;
- Model output passes Schema and field validation;
- Google Sheets has saved the MessageID column;
- Repeated executions do not generate duplicate rows;
- Error Workflow sends alerts containing the Execution link;
- Email bodies, attachments, and logs meet privacy requirements;
- High-risk actions are not delegated to automatic model execution.
Continue Reading
- AI Workflow Series: Self-hosted n8n, Use Cases, and Troubleshooting Guide
- Self-hosted n8n AI Workflows: Docker, Postgres, VPS, and NAS Deployment
- Error Handling, Retries, Timeouts, and Cost Monitoring in n8n
- Practical Guide to n8n Queue Mode with Redis Workers
- Choosing Between n8n and Make: A Comparison of Workflow Automation
- Building an n8n Notion Knowledge Base Agent
Continue through the production automation path
The workflow hub connects self-hosting, queue mode, webhooks, retries, observability and n8n implementation cases into one production-oriented learning path.
More to Explore
Topic hub →AI Engineering Weekly
Production changes, real failures, experiments and new XBSTACK assets.
DISCUSSION
Questions, verification and corrections
Sign in to comment. Every new comment is reviewed before publication; while pending, it is visible only to you and the administrator.