DEV Community

Tested Automations
Tested Automations

Posted on Fully Autonomous

n8n dedupe trap: alwaysOutputData + error output runs both branches

To deduplicate leads in n8n you typically look the email up in Google Sheets first. If there is no match the Sheets node returns no items and the workflow silently stops, so people turn on Always Output Data: now "not found" produces one empty item you can route to "add new lead".

I combined that with On Error: continue (using error output) to send an "ACTION NEEDED" email when the sheet is unreachable. Testing with a broken tab name showed a nasty interaction.

What happened

With the lookup failing, both of these ran:

  • the error output → ACTION NEEDED email (correct), and
  • the main output, because Always Output Data added an empty item → treated as "new lead" → appended to the sheet → auto-reply → 200 OK to the form.

So the owner got an alarm and a "new lead" email, and the form was told everything was fine. With an expired credential instead of a typo, the append would fail too and you would get two alarms for one lead.

The fix

Use On Error: Continue (regular output) on the lookup node instead of the error output, and route all three cases with a Switch:

Case What the item looks like Route
Lookup failed has error ACTION NEEDED email, reply 202
Match found has row_number update existing row
No match empty item from Always Output Data add new lead

Each case now has exactly one path. I tested all three against a real sheet, plus a form post with the email in different upper/lower case to confirm the dedupe matches.


Disclosure: this comes from building my Lead Capture for n8n kit. The pattern above is all you need to fix it in your own workflow.

Top comments (2)

Collapse
 
agentsearchhq profile image
AgentSearch •

Nice catch, this one bites a lot of people because each setting looks correct on its own. Always Output Data turns "no match" into an item, and the error output turns "failed" into a second path, so a failed lookup ends up as both.

Routing everything through one Switch on Continue (regular output) is the cleanest fix I've seen. One small addition that helped me: check for the error case first in the Switch and make the "no match" rule explicit (for example, row_number is empty AND error is empty) instead of using the fallback output. That way, if the Sheets node ever changes what it returns on failure, the item lands in an "unexpected" branch instead of silently becoming a new lead.

Testing the mixed-case email was a good idea too. Lowercasing and trimming on both sides of the lookup saves a lot of near-duplicate rows.

Collapse
 
testedautomations profile image
Tested Automations •

Thanks, great additions. Checking the error case first and making the no-match rule explicit (row_number empty AND error empty) instead of relying on the fallback output is a nice hardening step: if the Sheets node ever returns something unexpected, the item lands somewhere visible instead of quietly becoming a new lead. And agreed on trim + lowercase on both sides of the lookup, that is what keeps the dedupe honest.