AI Debugging and Root Cause Analysis for Failed Executions - n8n Workflow

Automatically debug failed n8n workflows using Gemini 2.5 Pro. This powerful n8n template provides AI-driven root cause analysis, suggested fixes, and immediate email notification.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

n8n instance administrators responsible for monitoring automation reliability.
Developers needing instant, actionable debugging assistance for complex n8n workflow failures.
Users looking for advanced n8n templates for self-healing and proactive error management.
Anyone running critical business automations who needs to minimize downtime when an n8n node fails.

Overview

Stop spending time manually digging through logs to understand why your automations break. This advanced n8n workflow sets up a 'debug watchdog' using an AI agent (like Gemini 2.5 Pro) to provide instant, detailed troubleshooting.

When any other n8n workflow fails, this solution automatically triggers. It captures the full context—including the specific error message and the entire JSON structure of the failed n8n workflow—and passes it to the AI. The AI acts as an expert n8n developer, performing a Root Cause Analysis and generating clear, step-by-step fix suggestions, which are then delivered immediately to your inbox. This shifts error management from reactive investigation to proactive resolution, significantly boosting the stability of your n8n environment.

How it Works

This automation is triggered by the specialized n8n trigger designed for instance-wide error detection, ensuring high availability for your n8n templates.


  1. Error Detection: The process begins instantly when the built-in Error Trigger n8n node catches an execution failure in any other workflow within your n8n instance.

  2. Context Retrieval: A crucial step involves using an HTTP Request n8n node and the n8n API to dynamically fetch the complete JSON definition of the failed workflow, giving the AI full context.

  3. AI Analysis Preparation: The data—including the error message, failed n8n node type, and the full workflow JSON—is compiled into a detailed prompt.

  4. Root Cause Diagnosis: A Langchain Agent node, leveraging the power of Gemini 2.5 Pro, processes this context. The AI, instructed via a system prompt to act as an expert debugger, analyzes the failed n8n node and its preceding steps to determine the root cause and output a suggested fix in Markdown format.

  5. Notification Formatting: A Convert Markdown to HTML n8n node ensures the AI's technical analysis is beautifully formatted for email readability.

  6. Final Alert: The workflow concludes by using the Send Debugging Email n8n node (Gmail) to send a comprehensive report, which includes a direct link to the failed execution, the raw error details, and the AI's detailed analysis.

Installation Guide

To deploy and utilize this powerful n8n workflow, follow these setup steps:

1. Import the n8n Template

Copy the provided JSON code.
In your n8n instance, click + New or Workflows and select Import from JSON.

2. Configure n8n API Access (Get Workflow JSON Node)

This n8n node requires credentials to call your n8n instance API to retrieve the failed workflow's structure.
Create API Key: Go to Settings > API in your n8n editor and create a new API key.
Create Credential: In the 'Get Workflow JSON' n8n node, create a new Generic Credential (type: HTTP Header Auth).
Header Name: X-N8N-API-KEY
Header Value: Paste the API key you generated.

3. Set Environment Variable

This workflow uses the N8NEDITORBASE_URL variable to build dynamic links to the failed execution. This must be set in your n8n environment variables (e.g., Docker, Cloud).
Value Example: https://my-n8n.example.com

4. Configure AI Credentials (Gemini 2.5 Pro Node)

The workflow uses the OpenRouter service for flexibility in accessing models like Gemini 2.5 Pro.
Obtain your API key from your OpenRouter account.
Update the credentials in the 'Gemini 2.5 Pro' n8n node with your OpenRouter API key.

5. Configure Gmail Notification

In the 'Send Debugging Email' n8n node:
Update the Send To field with your desired recipient email address (EMAIL-GOES-HERE).
Connect your Gmail OAuth2 credential. (Ensure the account has permissions to send emails).

6. Activate the Workflow


  • Ensure the workflow is active. Since it uses an Error Trigger n8n trigger, it will automatically monitor all other active n8n templates for failures.

Node Details

This n8n workflow relies on a specific sequence of specialized n8n node types:

Error Trigger (n8n trigger):
Function: This is the entry n8n trigger point, activating instantly upon the failure of any other workflow execution in the n8n instance.
Key Configuration: None required; it automatically monitors the environment.

Get Workflow JSON (HTTP Request n8n node):
Function: Fetches the complete structural definition (JSON) of the failed n8n workflow from the n8n API, providing the AI with necessary context.
Key Configuration: Uses an expression to define the URL based on the environment variable and the failed workflow ID: =\{$\{$env.N8NEDITORBASEURL\}/api/v1/workflows/\{$json.workflow.id\}_\}, requiring X-N8N-API-KEY Header Authentication.

Gemini 2.5 Pro (Langchain OpenRouter Chat Model n8n node):
Function: Specifies the powerful AI model used for analysis.
Key Configuration: Model set to google/gemini-2.5-pro using OpenRouter credentials.

Debugger Agent (Langchain Agent n8n node):
Function: The central processing n8n node. It packages the execution context, error details, and the full workflow JSON into a single, detailed prompt for the AI.
Key Configuration: System message forces the AI persona: "You are an expert n8n automation developer and debugger."

Convert Markdown To HTML (Markdown n8n node):
Function: Transforms the AI's Markdown-formatted analysis into clean HTML, ensuring the output is visually appealing within the final email notification.
Key Configuration: Takes the output from the Debugger Agent as input.

Send Debugging Email (Gmail n8n node):
Function: The final action, sending the comprehensive failure report, execution link, and the HTML-rendered AI analysis to the administrator.
Key Configuration: Utilizes expressions to build a dynamic subject line and body containing error variables from the initial Error Trigger n8n node.

Related n8n Workflows

Free

Nodes: 7 Nodes
Updated: December 26 2025
View all
Created by
Ramsey Njire
Ramsey Njire

Featured*