# Limit n8n AI workflow alerts to three fields

> Source: <https://dev.to/polarisyyuxu/limit-n8n-ai-workflow-alerts-to-three-fields-4pib>
> Published: 2026-11-12 05:07:23+00:00

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.

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](https://docs.n8n.io/build/flow-logic/handle-errors-gracefully.md)

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](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.code)

``` js
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](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.errortrigger#error-data)

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](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.webhook#webhook-urls)

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.
