{
  "id": "9NxE0Ad0SC1SPfjb",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "\u2705 Error Handling Workflow",
  "tags": [],
  "nodes": [
    {
      "id": "d468bbe6-751d-4438-b859-cd1daa7ee8ce",
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        160,
        -224
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "795cbfbd-3f08-4c9d-a0be-0459c309ad73",
      "name": "Ignore Manual Failures",
      "type": "n8n-nodes-base.filter",
      "position": [
        384,
        -224
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8ddebc82-8d35-4e0c-a74e-6f2099699f48",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $('Error Trigger').item.json.execution.mode }}",
              "rightValue": "manual"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "2f6722be-39f7-478f-a47d-4a16002dc008",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        816,
        460
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "f30573e0-c346-47c2-99f5-b86d6310a109",
      "name": "Time Saved",
      "type": "n8n-nodes-base.timeSaved",
      "position": [
        832,
        -224
      ],
      "parameters": {
        "minutesSaved": 1
      },
      "typeVersion": 1
    },
    {
      "id": "8bd9894a-ec9a-443e-819b-be43a6fbc70a",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1360,
        720
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "data"
      },
      "typeVersion": 1
    },
    {
      "id": "fea0ae9a-650d-4816-b02b-a26f20dff39c",
      "name": "Update Last Emailed At",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        1616,
        720
      ],
      "parameters": {
        "columns": {
          "value": {
            "lastEmailedAt": "={{ $now }}"
          },
          "schema": [
            {
              "id": "workflowId",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "workflowId",
              "defaultMatch": false
            },
            {
              "id": "executionId",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "executionId",
              "defaultMatch": false
            },
            {
              "id": "errorMessage",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "errorMessage",
              "defaultMatch": false
            },
            {
              "id": "errorStack",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "errorStack",
              "defaultMatch": false
            },
            {
              "id": "lastNodeExecuted",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "lastNodeExecuted",
              "defaultMatch": false
            },
            {
              "id": "workflowName",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "workflowName",
              "defaultMatch": false
            },
            {
              "id": "executionDate",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "executionDate",
              "defaultMatch": false
            },
            {
              "id": "executionUrl",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "executionUrl",
              "defaultMatch": false
            },
            {
              "id": "lastEmailedAt",
              "type": "dateTime",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "lastEmailedAt",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "filters": {
          "conditions": [
            {
              "keyValue": "={{ $json.id }}"
            }
          ]
        },
        "options": {},
        "matchType": "allConditions",
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "zbjSiKe71GhTt8Pp",
          "cachedResultUrl": "/projects/NVPkP6ENY3Rv7l37/datatables/zbjSiKe71GhTt8Pp",
          "cachedResultName": "Workflow Errors"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "e23d7bed-2310-40ab-9d34-465d56ddcd28",
      "name": "Get Errors that were not Emailed",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        368,
        460
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "lastEmailedAt",
              "condition": "isEmpty"
            }
          ]
        },
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "zbjSiKe71GhTt8Pp",
          "cachedResultUrl": "/projects/NVPkP6ENY3Rv7l37/datatables/zbjSiKe71GhTt8Pp",
          "cachedResultName": "Workflow Errors"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "9cc66afe-89cb-4dbf-9aff-05c56e181521",
      "name": "map fields to data table",
      "type": "n8n-nodes-base.set",
      "position": [
        608,
        -224
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7132728e-a39a-478e-9fc0-1f71f5593425",
              "name": "workflowId",
              "type": "string",
              "value": "={{ $('Error Trigger').item.json.workflow.id }}"
            },
            {
              "id": "ca5be94a-3f39-423c-aa2e-a0103a8ae97e",
              "name": "executionId",
              "type": "string",
              "value": "={{ $('Error Trigger').item.json.execution.id }}"
            },
            {
              "id": "64f740de-a897-46fc-86cd-5e7004df1bc5",
              "name": "errorMessage",
              "type": "string",
              "value": "={{ $('Error Trigger').item.json.execution.error.message ?? $('Error Trigger').item.json.values().toJsonString() }}"
            },
            {
              "id": "e8f1f197-dbd0-44cc-bdf7-9e9318bd5922",
              "name": "errorStack",
              "type": "string",
              "value": "={{ $('Error Trigger').item.json.execution.error.stack }}"
            },
            {
              "id": "851b421d-8d24-407e-b42f-ebb985dd5e73",
              "name": "lastNodeExecuted",
              "type": "string",
              "value": "={{ $('Error Trigger').item.json.execution.lastNodeExecuted }}"
            },
            {
              "id": "bddb35ac-4d3a-432a-8896-f6a68d35f2a8",
              "name": "workflowName",
              "type": "string",
              "value": "={{ $('Error Trigger').item.json.workflow.name }}"
            },
            {
              "id": "1ef62897-61cd-4a43-ba06-b4c83ce5febb",
              "name": "executionDate",
              "type": "string",
              "value": "={{ $now.format('yyyy-MM-dd') }}"
            },
            {
              "id": "97ae6e2d-e7ab-4ed6-b393-9e79b8bf7974",
              "name": "executionUrl",
              "type": "string",
              "value": "={{ $('Error Trigger').item.json.execution.url }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "83076dd7-5b22-427d-8365-71279af62184",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1496,
        432
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "31f714b3-2931-4221-957a-270215a0c32d",
      "name": "AI Error Summarizer",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1488,
        208
      ],
      "parameters": {
        "text": "=Workflow Errors:  {{ JSON.stringify($('Aggregate').item.json.data) }}",
        "options": {
          "systemMessage": "You are my error summarizer agent. Your duty is to read through a list of errors, and provide a concise summary of the errors on my n8n workflows in well summarised pointers that is easy to go through and also provide some inputs on resolving those errors. Also give some quantitative representation for the number of errors. Give more priority to errors that have occurred many times. Do not cover all details of the errors, just a concise summary.\n\nGive me the output in html format, nothing else, no extra triple backticks or extra strings.\n\nI've given you a Calculator tool, if you find a need, but its not a necessity.\n\nTime right now: {{ $now }}"
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "e38c352e-5e5f-43c2-82a2-baaa24da284b",
      "name": "Email Error Details",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1840,
        312
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "={{ $json.output[0].content[0].text }}\n<br><br>\n{{ $('Code in JavaScript').item.json.html }}",
        "options": {
          "senderName": "Harshal Patil",
          "appendAttribution": false
        },
        "subject": "=n8n Workflow Errors - {{ $now.minus(1,'days').format('yyyy-MM-dd') }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "dd482380-098a-439e-9539-31407defc725",
      "name": "Insert Error Details",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        1056,
        -224
      ],
      "parameters": {
        "columns": {
          "value": {
            "errorStack": "={{ $('Error Trigger').item.json.execution.error.stack }}",
            "workflowId": "={{ $('Error Trigger').item.json.workflow.id }}",
            "executionId": "={{ $('Error Trigger').item.json.execution.id }}",
            "errorMessage": "={{ $('Error Trigger').item.json.execution.error.message }}",
            "executionUrl": "={{ $('Error Trigger').item.json.execution.url }}",
            "workflowName": "={{ $('Error Trigger').item.json.workflow.name }}",
            "executionDate": "={{ $now.format('yyyy-MM-dd') }}",
            "lastNodeExecuted": "={{ $('Error Trigger').item.json.execution.lastNodeExecuted }}"
          },
          "schema": [
            {
              "id": "workflowId",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "workflowId",
              "defaultMatch": false
            },
            {
              "id": "executionId",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "executionId",
              "defaultMatch": false
            },
            {
              "id": "errorMessage",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "errorMessage",
              "defaultMatch": false
            },
            {
              "id": "errorStack",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "errorStack",
              "defaultMatch": false
            },
            {
              "id": "lastNodeExecuted",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "lastNodeExecuted",
              "defaultMatch": false
            },
            {
              "id": "workflowName",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "workflowName",
              "defaultMatch": false
            },
            {
              "id": "executionDate",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "executionDate",
              "defaultMatch": false
            },
            {
              "id": "executionUrl",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "executionUrl",
              "defaultMatch": false
            },
            {
              "id": "lastEmailedAt",
              "type": "dateTime",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "lastEmailedAt",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "zbjSiKe71GhTt8Pp",
          "cachedResultUrl": "/projects/NVPkP6ENY3Rv7l37/datatables/zbjSiKe71GhTt8Pp",
          "cachedResultName": "Workflow Errors"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "5020cc8e-f172-4007-9fa1-c669066cf4b9",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -672,
        -16
      ],
      "parameters": {
        "width": 448,
        "height": 512,
        "content": "## Automated error monitoring and reporting system\n\n**How it works:**\n1. Error Trigger activates on workflow failures. Ignore Manual Failures filters out testing runs.\n2. Error details (workflow name, timestamp, error message, failed node) are extracted and inserted into the data table.\n3. Every hour, unemailed errors are retrieved. If >5 errors exist or oldest error >24 hours, report generation starts.\n4. AI summarizes errors with tips, generates HTML table, and emails the complete report.\n\n**Setup steps:**\n- Configure Error Trigger to monitor your workflows\n- Set up Gmail credentials for notifications\n- Configure OpenAI API key\n- Customize data table schema\n- Adjust schedule in Run every hour node"
      },
      "typeVersion": 1
    },
    {
      "id": "71ef77a5-6918-41c6-8ff0-37a0883b22b2",
      "name": "Calculator",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "position": [
        1624,
        432
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "30e8edaf-def4-4a18-821a-b439a095026c",
      "name": "Sort",
      "type": "n8n-nodes-base.sort",
      "position": [
        592,
        460
      ],
      "parameters": {
        "options": {},
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "createdAt"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "eeaba522-a90a-4450-ad29-46dc0c9d66b6",
      "name": "high error count or been a day1",
      "type": "n8n-nodes-base.filter",
      "position": [
        1040,
        460
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "f8de07d3-6fa6-466c-be6d-438aef94a5da",
              "operator": {
                "type": "array",
                "operation": "lengthGt",
                "rightType": "number"
              },
              "leftValue": "={{ $json.data }}",
              "rightValue": 5
            },
            {
              "id": "5f907458-d775-445b-8517-1461eb84f68c",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ DateTime.now().diff(DateTime.fromISO($('Sort').first()?.json?.createdAt), 'hours').hours.round() >= 24 }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "a0e8e245-d98c-4832-8138-b0bca4e7f6af",
      "name": "Run every hour",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        144,
        460
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "7378503f-bd85-4fdb-9144-a1fcb1354455",
      "name": "Generate Workflow Errors Table HTML",
      "type": "n8n-nodes-base.html",
      "position": [
        1264,
        312
      ],
      "parameters": {
        "html": "=<!DOCTYPE html>\n\n<html>\n<head>\n  <meta charset=\"UTF-8\" />\n  <title>Workflow Errors</title>\n</head>\n<body>\n  <table style=\"width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px;\">\n    <thead>\n      <tr style=\"background-color: #4CAF50; color: white;\">\n        <th style=\"padding: 12px; text-align: left; border: 1px solid #ddd;\">Workflow Name</th>\n        <th style=\"padding: 12px; text-align: left; border: 1px solid #ddd;\">Execution Date</th>\n        <th style=\"padding: 12px; text-align: left; border: 1px solid #ddd;\">Execution Timestamp (UTC)</th>\n        <th style=\"padding: 12px; text-align: left; border: 1px solid #ddd;\">Failed Node</th>\n        <th style=\"padding: 12px; text-align: left; border: 1px solid #ddd;\">Error Message</th>\n        <th style=\"padding: 12px; text-align: left; border: 1px solid #ddd;\">View Execution</th>\n      </tr>\n    </thead>\n    <tbody>\n      {{ $('Aggregate').item.json.data.map((record, index) => {\n        const bgColor = index % 2 === 0 ? '#f9f9f9' : '#ffffff';\n        const executionTimestamp = record.createdAt ? new Date(record.createdAt).toISOString().replace('T', ' ').replace('Z', '').slice(0, 19) : 'N/A';\n        return `\n          <tr style=\"background-color: ${bgColor};\">\n            <td style=\"padding: 10px; border: 1px solid #ddd;\">${record.workflowName || 'N/A'}</td>\n            <td style=\"padding: 10px; border: 1px solid #ddd;\">${record.executionDate || 'N/A'}</td>\n            <td style=\"padding: 10px; border: 1px solid #ddd;\">${executionTimestamp}</td>\n            <td style=\"padding: 10px; border: 1px solid #ddd;\">${record.lastNodeExecuted || 'N/A'}</td>\n            <td style=\"padding: 10px; border: 1px solid #ddd; max-width: 300px; word-wrap: break-word;\">${record.errorMessage || 'N/A'}</td>\n            <td style=\"padding: 10px; border: 1px solid #ddd;\"><a href=\"${record.executionUrl}\" target=\"_blank\" style=\"color: #2196F3; text-decoration: none;\">View</a></td>\n          </tr>\n        `;\n      }).join('') }}\n    </tbody>\n  </table>\n</body>\n</html>"
      },
      "typeVersion": 1.2
    },
    {
      "id": "26d49e97-fed8-453e-929e-c7f3e89d9f9d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1216,
        96
      ],
      "parameters": {
        "color": 7,
        "width": 880,
        "height": 464,
        "content": "## Generate & Send Error Notification\nConsolidate errors into a single table with an email with AI Powered Insights & sends the Email"
      },
      "typeVersion": 1
    },
    {
      "id": "6065144a-c242-494e-9c0d-e54ecd239a42",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1312,
        624
      ],
      "parameters": {
        "color": 7,
        "width": 608,
        "height": 336,
        "content": "## Update Errors that were notified\nUpdate Errors that were emailed to they're not picked up next time"
      },
      "typeVersion": 1
    },
    {
      "id": "8572a97f-f58b-4b96-a781-deeb5f18fdf7",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        336,
        336
      ],
      "parameters": {
        "color": 7,
        "width": 832,
        "height": 336,
        "content": "## Filter & Prepare errors to report\nSort errors that are to be reported and filter only if error count is beyond a threshold"
      },
      "typeVersion": 1
    },
    {
      "id": "7a2030b0-dd2e-4b04-9909-a5dc518e6059",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        304,
        -352
      ],
      "parameters": {
        "color": 7,
        "width": 960,
        "height": 384,
        "content": "## Store errors\nIgnore Manual Errors and store automatic errors into our Error Data Table"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "callerPolicy": "workflowsFromSameOwner",
    "timeSavedMode": "dynamic",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "64f25ddb-7473-4107-ac0e-2cb5baab047b",
  "connections": {
    "Sort": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "high error count or been a day1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Update Last Emailed At",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "AI Error Summarizer",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Time Saved": {
      "main": [
        [
          {
            "node": "Insert Error Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Ignore Manual Failures",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run every hour": {
      "main": [
        [
          {
            "node": "Get Errors that were not Emailed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Error Summarizer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Error Summarizer": {
      "main": [
        [
          {
            "node": "Email Error Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Error Details": {
      "main": [
        []
      ]
    },
    "Ignore Manual Failures": {
      "main": [
        [
          {
            "node": "map fields to data table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "map fields to data table": {
      "main": [
        [
          {
            "node": "Time Saved",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "high error count or been a day1": {
      "main": [
        [
          {
            "node": "Generate Workflow Errors Table HTML",
            "type": "main",
            "index": 0
          },
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Errors that were not Emailed": {
      "main": [
        [
          {
            "node": "Sort",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Workflow Errors Table HTML": {
      "main": [
        [
          {
            "node": "AI Error Summarizer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}