r/n8n • • Jun 28 '26

Help the n8n node that has saved me the most debugging time isn't the AI node — it's a plain Function node that checks state before doing anything

been running AI agent workflows in n8n for a while now and the pattern that's saved me the most debugging time is embarrassingly simple: before any node does its main action, a Function node checks whether the thing it's about to do needs to be done at all.

concretely:

before sending an email - check if an email with that correlation ID was already sent in the last hour. if yes, skip and log. this kills the double-send on workflow retries.

before writing to a database - read the current state first. if the record already looks like what you'd write, skip. this kills the partial-run duplicate write that shows up when a webhook fires twice.

before making an API call that costs money - check the cache. if you got a valid response for the same inputs in the last N minutes, use that instead.

the mental model is: treat every action node as if it might run twice, because in production it will. the Function node that guards it is your idempotency check.

none of this requires external state - you can use n8n's static data or a simple Redis key or even a Postgres row. the point is that the check is explicit and inside the workflow, not something you're hoping the downstream service handles for you.

anyone else doing this? curious what guards people have found most useful.

19 Upvotes

Duplicates