Free Code node that fails a run when the data is empty or a key field is missing

Hi all. I run Velox, a one-person shop that helps small businesses automate their work. I made the Code node below, and it is free. While reading threads here and on GitHub in October, I found 28 reports of runs that showed Success while the data was wrong. Most of them were a node returning 0 items, a key field coming back empty, or the item count dropping. The Error Workflow doesn’t fire for any of these, since nothing actually crashed.

I put together a small Code node for the first two. You place it after the node you want to check. If the items are empty (or only {}), or a required field is missing or empty, it throws an error, so the run is marked as failed and your usual Error Workflow sends the alert. If the data looks fine, the items pass through unchanged.

[Your node] → [Silent Data Failure Guard] → [rest of the workflow]
(Always Output Data: on)

Two things that tripped me up while testing on n8n 2.45.5, in case they help someone even without this node:

  1. The node before the check needs Always Output Data turned on. Otherwise n8n doesn’t run anything after a node that returns 0 items, and the run still shows Success.
  2. An Error Workflow has to be published, or it never gets called. The editor shows no warning; only the server log says is not active and cannot be executed.

Here’s the node, with an example workflow, an email alert workflow, and the test cases I used: GitHub - velox-jp/n8n-silent-data-failure-guard: Free n8n Code node that fails a run when the data comes back empty or a key field is missing · GitHub

If you’ve run into a silent failure that this wouldn’t catch, I’d like to hear about it.

The distinction between a failed execution and a successful execution with invalid data is really important

One extra check I’d consider is comparing expected vs. actual record counts where an expected count is available, especially in CRM sync or lead-routing workflows. A run can return items that look valid while silently dropping records upstream.

I’d also separate an expected empty result from an unexpected one, so the guard doesn’t trigger false alarms

This kind of check makes workflow monitoring far more useful than just relying on execution status

Great i Velox insight, ! I agree that validating record counts is an important step in detecting silent data loss.

I would take this a step further by combining three levels of validation in n8n:

  1. Expected vs. Actual Record Counts: Compare the expected number of records with the actual output, using a reliable baseline from the source system or previous processing step.

  2. Data Integrity Checks: Validate required fields such as customer IDs, email addresses, and other critical values to ensure that incomplete records don’t pass through unnoticed.

  3. Record-Level Reconciliation: Use unique IDs to identify missing or duplicated records, especially in CRM synchronization and lead-routing workflows.

One important consideration is to account for intentional filtering and legitimate empty results. Otherwise, the validation itself could generate false positives.

If an unexpected mismatch or validation failure is detected, the Code node can throw an error, allowing the configured Error Workflow to notify the team through Slack or email.

I believe combining these checks would help move n8n monitoring beyond simply checking whether an execution succeeded and towards verifying whether the workflow actually processed the correct data.

Thanks for sharing this valuable approach!

Nice approach. I’d add a few test cases before relying on this guard in production:

  1. A genuinely valid empty result, so intentional filtering doesn’t trigger false alarms.

  2. An empty object or missing required field.

  3. Unexpected item-count reduction between nodes.

  4. A validator failure that could itself be swallowed by downstream Continue On Error handling.

One other important distinction: the required fields and expected item counts should be configurable per workflow or node. Zero items aren’t always an error.

A static workflow review could also flag whether the guard is connected correctly, whether Always Output Data is enabled where needed, and whether an Error Workflow is configured. But an actual test execution is still necessary to confirm the guard behaves correctly.

I’d keep configuration findings separate from runtime behavior that hasn’t been verified.

Thanks, all. Replies to a few of the points:

@Mahdi_Eqbal, @Sardar1: comparing expected and actual record counts is a good addition. This node does not do it. It checks only two things: that the items are not empty, and that one required field is present and not blank. A drop from 500 items to 5 would pass.

GauravStack: the required field is one constant at the top of the code (const REQUIRED_FIELD = 'id';), so it is set per workflow. Zero items is not always an error, so I would place the guard only after nodes where empty is unexpected. For a normal empty result, branch before it (an If node) so that those items never reach the guard. To catch an unexpected empty result, turn on Always Output Data on the node before the guard, or n8n skips the guard.

On your point about a failure being swallowed by Continue On Error: I have not tested that. If Continue On Error is turned on for the guard node itself, it would swallow the guard’s error, so leave it off there. I only ran the cases in the repo, on self-hosted n8n 2.45.5.