Google Sheets Loop & AI Automation with n8n

The Problem

The client needed an automated way to process email data, generate AI replies, and save results to Google Sheets — but without creating duplicate rows. Their old loop logic in Make.com was complex and caused repeated entries or manual clean-ups. When they tried doing this in n8n, it kept looping the whole workflow and overloaded the sheet, or skipped checks for duplicates.

The Solution

We designed a reliable, clean n8n workflow that automatically:
Checks if a row already exists using a unique Email ID
Loops through each item one by one
Only appends new rows, skipping any duplicates
Generates AI replies with ChatGPT, merges them with the data, and saves them back to Sheets — without any manual work.

How It Works — Step by Step

  1. 1. The workflow starts with a manual trigger or schedule.
  2. 2. A Google Sheets node fetches all emails from a master sheet (Mail Sheet).
  3. 3. A Code node formats the email fields into a clean user prompt.
  4. 4. The prompt is sent to OpenAI ChatGPT to generate a smart response.
  5. 5. The AI response is merged back with the original email data.
  6. 6. A loop node (batch size 1) runs through each email one at a time.
  7. 7. A Google Sheets node checks if the email ID already exists in the final sheet.
  8. 8. A Switch node checks the lookup result: if empty → append; if found → skip.
  9. 9. A NoOp node ensures the loop continues until all emails are processed.

Why This Works

The key trick is using the “Always Output Data” option on the Google Sheets lookup. If a row is missing, the node outputs an empty object. The Switch node checks if the returned object has keys — if not, the row is new, so we add it. This ensures no duplicates, no sheet overload, and a 100% clean dataset.

Workflow Highlights

  • Manual or scheduled trigger for flexibility
  • Unique Email ID check to prevent duplicate rows
  • Clean loop over items, one at a time, for stability
  • Smart ChatGPT integration for auto-generated replies
  • NoOp node keeps the flow stable to the end

Client Results

This upgraded flow gives our client:
Zero manual checking for duplicate data
Fully automated AI reply generation
No data loss, no repeated rows
Clean, organized sheets every time

Want a custom n8n automation for your workflows? We help you migrate, upgrade, and automate smarter — with simple logic that saves you time.

GET STARTED

If you would like to work with us or just want to get in touch, we’d love to hear from you!