Tips > Reliability & Performance

Use the Stop and Error Node for Intentional Workflow Halts

When your workflow detects an invalid state that should not continue -- bad input data, missing prerequisites, or a violated business rule -- use the Stop

The Stop and Error node halts a workflow deliberately with a clear, descriptive message when it detects an invalid state, such as bad input or a violated business rule. Unlike an unexpected crash, it is a controlled stop that documents exactly what went wrong, and it is visible on the canvas so anyone reading the workflow sees the intent.

What is the Stop and Error node?

When your workflow detects an invalid state that should not continue -- bad input data, missing prerequisites, or a violated business rule -- use the Stop and Error node to halt execution with a clear, descriptive message. This is different from an unexpected error; it is a deliberate, controlled stop that communicates exactly what went wrong.

Real-world example: An invoice processing workflow receives data from a webhook. Before processing, it checks that the invoice total matches the sum of line items. If they do not match, the workflow should stop immediately with a clear message rather than processing bad data.

How do you halt a workflow on invalid data?

Workflow structure:

[Webhook] --> [Code: Validate Invoice] --> [IF: Valid?]
                                              |
                                     +-------+-------+
                                     |               |
                                  [True]          [False]
                                     |               |
                              [Process Invoice]  [Stop and Error]

Validation Code node:

// Code node: "Validate Invoice"
const invoice = $input.first().json.body;

const errors = [];

// Check required fields
if (!invoice.invoice_id) errors.push('Missing invoice_id');
if (!invoice.customer_id) errors.push('Missing customer_id');
if (!invoice.line_items || invoice.line_items.length === 0) {
  errors.push('No line items');
}

// Check total matches line items
if (invoice.line_items && invoice.total !== undefined) {
  const calculatedTotal = invoice.line_items.reduce(
    (sum, item) => sum + (item.quantity * item.unit_price), 0
  );
  const roundedCalculated = Math.round(calculatedTotal * 100) / 100;
  const roundedTotal = Math.round(invoice.total * 100) / 100;

  if (roundedCalculated !== roundedTotal) {
    errors.push(
      `Total mismatch: stated ${roundedTotal}, calculated ${roundedCalculated}`
    );
  }
}

return [{
  json: {
    valid: errors.length === 0,
    errors,
    invoice
  }
}];

Stop and Error node configuration:

# Stop and Error node settings

Error Type: Workflow
Error Message: >
  Invoice validation failed for invoice {{ $json.invoice.invoice_id }}:
  {{ $json.errors.join('; ') }}.
  Workflow halted to prevent processing invalid data.
  Source customer: {{ $json.invoice.customer_id }}.

The error message appears in:

- The execution log (with full details)
- The Error Workflow notification (if configured)
- The Respond to Webhook response (if using Respond to Webhook node on the error branch)

When should you use Stop and Error instead of throwing?

Tip: Stop and Error vs. throwing in Code node Both halt the workflow, but Stop and Error is a visible node in the canvas that clearly communicates intent to anyone reading the workflow. It also provides a structured error message. Throwing an error in a Code node works but looks like a bug rather than intentional behavior.

Use Stop and Error as guardrails throughout your workflow to catch invalid states early and communicate clearly why processing was halted.

Related: Use "Pin Data" to Freeze Node Output · Break Large Workflows into Sub-Workflows

Showcase builds

19 complete workflows from my own projects, each with its n8n workflow JSON to import. Showcase entries link the file at the end of the article.

See the showcase builds

Keep reading

190 entries grouped by topic, from first workflow to queue mode. Free, no signup.

Browse the encyclopedia

Need it built?

I design, build and run n8n systems for clients. Every engagement starts with a $1,500 diagnostic audit, credited toward the build.

Book an introductory call