Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 2 min read

Limit n8n AI workflow alerts to three fields

An AI workflow failure can leave request or response details in its error payload. For an alert sent to Slack or email, a workflow label, a failure phase, and an execution ID are enough to start the investigation.

An AI workflow failure can leave request or response details in its error payload. For an alert sent to Slack or email, a workflow label, a failure phase, and an execution ID are enough to start the investigation.

Build the alert from approved fields

Save an error workflow with Error Trigger β†’ Code β†’ Slack or Email. In the AI workflow’s settings, select it under Error workflow. You can assign one error workflow to multiple workflows. n8n error workflow setup

Set the Code node to JavaScript and Run Once for All Items. Replace the synthetic workflow ID 42 and label support-triage with values you’ve approved for the alert destination. n8n Code node

const event = $input.first().json;
const workflowLabels = new Map([["42", "support-triage"]]);
const workflow = workflowLabels.get(String(event.workflow?.id ?? "")) ?? "unmapped";
const phase = event.trigger ? "trigger" : event.execution ? "execution" : "unknown";
const alert = { workflow, phase };

const rawId = event.execution?.id;
const id = typeof rawId === "string" ? rawId : Number.isSafeInteger(rawId) ? String(rawId) : "";
if (/^[0-9]{1,20}$/.test(id)) {
  alert.executionId = id;
}

return [{ json: alert }];

Build the outgoing message using only workflow, phase, and executionId when present. A saved failure could produce support-triage Β· execution Β· 231. A failure in the trigger could produce support-triage Β· trigger. An unsaved execution can also lack an ID, so use the event’s trigger and execution fields to distinguish the two. n8n Error Trigger payload

Test with a harmless failure

In staging, use an authenticated Webhook β†’ Stop And Error workflow with the synthetic message ALERT_TEST_ONLY. Assign the error workflow and set the alert destination to a test channel. Publish the staging workflow, call the webhook’s Production URL once, then unpublish it. Error Trigger runs on automatic failures, so Execute workflow in the editor won’t exercise it. Webhook URL behavior

Verify that the alert arrives with the expected label and phase. Check that the error message, stack, and execution URL are absent. Review who can access execution data and how long it’s retained separately from the alert.

The JavaScript was checked with synthetic inputs. Delivery through a live n8n workflow is untested.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.