{ "name": "n8n Silent-Failure & AI Agent Watchdog (Zero-Trust)", "nodes": [ { "parameters": { "content": "## Quick Setup (30 Seconds)\n1. Set this workflow as your instance **Error Workflow** (`Workflow Settings -> Error Workflow`) or call it as a Sub-Workflow when an AI Agent returns `[]` or invalid JSON.\n2. The **Local Secret Scrubber** runs 100% inside your n8n instance and strips API keys (`sk_`, `ghp_`, `re_`, `whsec_`, JWTs, Bearer tokens, emails) BEFORE any alert leaves.\n3. Connect your Slack, Telegram, Discord, or Email node to **Format Diagnostic Alert**.\n\nDocs & Post-Mortems: https://hooktriage.com", "height": 260, "width": 430, "color": 4 }, "id": "sticky-setup-guide", "name": "Setup Guide (Read First)", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 160, 20 ] }, { "parameters": { "content": "## Security Audit Guarantee\n- 100% Native n8n Nodes (`Error Trigger`, `Code`, `Set`)\n- **Zero external HTTP calls by default** (your keys never leave your server)\n- Detects both hard crashes and silent failures (empty arrays `[]`, HTTP `429` rate limits, `401/403` OAuth token deadlocks)", "height": 220, "width": 380, "color": 6 }, "id": "sticky-security-audit", "name": "Zero-Trust Security Guarantee", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 630, 40 ] }, { "parameters": {}, "id": "watchdog-error-trigger", "name": "Error Trigger", "type": "n8n-nodes-base.errorTrigger", "typeVersion": 1, "position": [ 220, 340 ] }, { "parameters": { "jsCode": "// Zero-Trust Local Secret & PII Scrubber + Root-Cause Classifier\n// Runs 100% locally inside your n8n instance.\nconst scrub = (val) => {\n if (!val) return \"\";\n return String(val)\n .replace(/\\b(sk_live_|sk_test_|sk-|re_|ghp_|gho_|whsec_|xox[baprs]-|AIza)[A-Za-z0-9_/+=-]{10,}\\b/g, \"[REDACTED_KEY]\")\n .replace(/\\bAKIA[0-9A-Z]{16}\\b/g, \"[REDACTED_AWS]\")\n .replace(/\\beyJ[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{6,}\\b/g, \"[REDACTED_JWT]\")\n .replace(/(Bearer\\s+)[A-Za-z0-9._-]{12,}/gi, \"$1[REDACTED_TOKEN]\")\n .replace(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}/g, \"[REDACTED_EMAIL]\")\n .slice(0, 2200);\n};\n\nconst classifyHint = (msg, nodeName) => {\n const m = (msg || \"\").toLowerCase();\n if (m.includes(\"429\") || m.includes(\"rate limit\")) {\n return \"API Rate Limit (429): Enable Retry On Fail + Exponential Backoff (2s-8s) + split batch size.\";\n }\n if (m.includes(\"401\") || m.includes(\"403\") || m.includes(\"oauth\") || m.includes(\"token\")) {\n return \"Auth / OAuth Deadlock: Token expired or missing scope; verify refresh token lock under concurrent runs.\";\n }\n if (m.includes(\"timeout\") || m.includes(\"econnreset\") || m.includes(\"504\") || m.includes(\"502\")) {\n return \"Upstream Timeout / 5xx: Add HTTP Request timeout cap + fallback Respond to Webhook before 5s platform cutoffs.\";\n }\n if (m.includes(\"json\") || m.includes(\"unexpected\") || m.includes(\"empty\")) {\n return \"Silent Output / Schema Drift: Guard AI Agent / JSON Parse output with fallback IF node before downstream writes.\";\n }\n return `Inspect '${nodeName}' input schema, add timeout/retry options, and capture failed item ID for dead-letter replay.`;\n};\n\nconst item = $input.first().json || {};\nconst wf = item.workflow || {};\nconst ex = item.execution || {};\nconst err = ex.error || item.error || {};\nconst lastNode = scrub(ex.lastNodeExecuted || (err.node && err.node.name) || item.last_node || \"Unknown Node\").slice(0, 120);\nconst errMsg = scrub(err.message || item.message || \"Silent workflow failure or unexpected empty output\");\n\nreturn [{\n json: {\n timestamp_utc: new Date().toISOString(),\n workflow_id: String(wf.id || \"unknown\").slice(0, 40),\n workflow_name: scrub(wf.name || item.workflow_name || \"Unnamed n8n Workflow\").slice(0, 140),\n execution_id: String(ex.id || \"n/a\").slice(0, 40),\n last_node: lastNode,\n error_message: errMsg,\n recommended_fix_hint: classifyHint(errMsg, lastNode),\n execution_url: ex.url ? scrub(ex.url) : \"Check n8n Executions tab\"\n }\n}];" }, "id": "watchdog-local-scrubber", "name": "Zero-Trust Local Scrubber & Classifier", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 500, 340 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "alert-title-field", "name": "alert_title", "type": "string", "value": "=[n8n Watchdog] {{ $json.workflow_name }} \u2014 Node: {{ $json.last_node }}" }, { "id": "alert-body-field", "name": "alert_message", "type": "string", "value": "=Workflow: {{ $json.workflow_name }} ({{ $json.workflow_id }})\nExecution: {{ $json.execution_id }} | Failed Node: {{ $json.last_node }}\nSanitized Error: {{ $json.error_message }}\nQuick Triage Hint: {{ $json.recommended_fix_hint }}\nRef: {{ $json.execution_url }}" } ] } }, "id": "watchdog-format-alert", "name": "Format Diagnostic Alert (Connect Slack / Telegram / Email)", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 780, 340 ] } ], "connections": { "Error Trigger": { "main": [ [ { "node": "Zero-Trust Local Scrubber & Classifier", "type": "main", "index": 0 } ] ] }, "Zero-Trust Local Scrubber & Classifier": { "main": [ [ { "node": "Format Diagnostic Alert (Connect Slack / Telegram / Email)", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" } }