See llms.txt for all machine-readable content.

Back to Templates

Guard workflows and log incidents with the n8n API, data tables and email

Quick overview

This workflow provides an n8n “safety net” by logging failed workflow executions to an n8n Data Table and sending email alerts, and by fingerprinting workflows nightly or via a secured webhook using the n8n API to detect suspicious edits and store clean versions.

How it works

  1. Triggers when another workflow errors (as an n8n error workflow), on a nightly schedule, or via a Header Auth–protected webhook for before/after edit checks.
  2. Routes the incoming event to either the incident-handling path or the workflow snapshot/guard path based on the payload.
  3. For incidents, extracts key failure details (workflow, execution ID, failed node, error message, and execution URL) and inserts them into an n8n Data Table as a dead-letter log.
  4. Sends an SMTP email alert with the incident details even if the Data Table insert fails.
  5. For snapshots, uses the n8n API to fetch workflows and computes a content-based fingerprint (hash, node count, non-ASCII counts, U+FFFD replacement characters, and question marks).
  6. Compares the current fingerprints to the latest stored fingerprints in an n8n Data Table, stores a new workflow version and updates the latest fingerprint when changes are safe, and flags warnings/errors for suspicious changes.
  7. Emails a report when warnings or errors are detected, and for webhook-driven checks responds with JSON and an HTTP 409 status on errors so calling scripts can stop a deployment.

Setup

  1. Create three n8n Data Tables named workflow_incidents, workflow_versions, and workflow_fingerprints with the columns expected by the insert/upsert steps.
  2. Add credentials for n8n API (to read workflows), SMTP (to send alerts), and Header Auth (to protect the webhook endpoint).
  3. Update the recipient and sender addresses in the workflow settings values (alertTo and alertFrom).
  4. Activate (publish) this workflow so the nightly schedule and the webhook run, then set it as the "Error workflow" in the settings of each workflow you want to protect.
  5. For API-based edits, call the webhook with {"action":"before"|"after","workflowId":"<id>"} and ensure your script stops if the response status is 409.

Requirements

  • n8n with data tables. Tested on n8n 2.47.7 (self-hosted).