ClaudeWorkPlanningAI score · PendingAI-assisted edit · no obvious prompt-injection riskn8n.io

n8n + Claude Self-Healing Data Pipeline: PostgreSQL Anomaly Detection & Auto-Remediation

Scheduled PostgreSQL fetch → statistical/ML anomaly detection → Claude classification & remediation planning → auto-execution → validation & notification

ExperiencedStepsWorkflowPrompt
Who
Data engineers, ops teams, organizations needing automated data quality monitoring
You get
Automatically detect data anomalies every 15 minutes, AI-classify and auto-remediate (fill nulls, cap outliers, reformat schema, retry upstream), with human escalation on failure
You need
n8n · postgresql · slack · pagerduty · datadog

Constraints

Requires n8n instance, PostgreSQL database (source table, incident table, baseline table), Anthropic Claude API key, Slack workspace permissions, PagerDuty service ID and API key, DataDog API key. Template contains 46 nodes, 13 code nodes, 2 Anthropic AI nodes. Replace all <__PLACEHOLDER_VALUE__> parameters on first use.

What they did

Author rnair1996 published this workflow template in the n8n official template gallery, demonstrating a complete 46-node self-healing data pipeline system. The template uses a schedule trigger executing every 15 minutes, pulls data via PostgreSQL, performs statistical quality checks (null rate, IQR outliers, schema consistency) with JavaScript code nodes, compares against 7-day historical baselines and calculates trends. When anomalies are detected, it calls Claude-3-5-sonnet for classification and remediation planning, then executes one of four remediation actions based on the AI recommendation, validates results, notifies via Slack, logs to PostgreSQL, sends metrics to DataDog, and creates PagerDuty incidents for critical severity.

How it went

Author reports the template achieves automated anomaly detection, AI classification, auto-remediation, validation loop, and tiered alerting (author_report). Template is published on n8n official platform with status published. This site has not tested execution; reproduction=not_tested.

Worth knowing

Retry Upstream Data Fetch node is currently a placeholder implementation with comments indicating actual retry logic must be added; expectedSchema in schema remediation is hardcoded and must be adjusted for actual data; Claude output requires strict JSON format, non-standard JSON output will cause downstream parsing failures; all API keys are stored in plaintext in the Set Pipeline Parameters node, production environments should use n8n credential management instead; default parameters are anomalyScoreThreshold=0.75, nullThreshold=0.1, outlierIQRMultiplier=1.5 and should be tuned to data characteristics.

n8n workflow template

Structure checked · Not run-tested

Use “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.

Setup and test checklist

Credentials to connect

  • After import, connect your own credentials on auth-required nodes; author secrets are not included.

Configuration to replace

  • Source template is n8n public workflow #18820 (~46 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
  • Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.

Test input and expected output

  • Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
  • Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.

Template changes

  • Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
  • No business-logic edits; verify keys, quotas and privacy compliance before use.

Template retrieved: 2026-10-24

Steps

  1. Configure trigger and data connections

    After importing the template into n8n, configure the schedule trigger (default every 15 minutes) and the Set Pipeline Parameters node. Enter PostgreSQL connection details, source table name, Slack channel ID, PagerDuty service ID and API key, DataDog API key. Replace placeholders in nodes: <__PLACEHOLDER_VALUE__source_table_name__>, <__PLACEHOLDER_VALUE__Slack channel ID for notifications__>, <__PLACEHOLDER_VALUE__PagerDuty API key__>, <__PLACEHOLDER_VALUE__DataDog API key__>.

  2. Run statistical and ML anomaly detection

    Workflow executes automatically: Fetch Latest Data from PostgreSQL pulls last 15 minutes of data; Fetch Historical Baseline Data loads 7-day baseline; Compare with Historical Baseline calculates deviations; Calculate Trend Analysis Metrics computes moving averages and trends; Run ML-Based Anomaly Scoring combines 5 features (baseline deviation, trend velocity, historical pattern, statistical outliers, null rate) into 0-1 anomaly score. Run Statistical Quality Checks executes null rate, IQR outlier, and schema consistency checks.

  3. Claude classifies anomaly and plans remediation

    If anomaly score exceeds threshold (default 0.75) or statistical checks detect anomalies, Check If Anomaly Detected branches to AI Anomaly Classifier Agent. This node calls Claude-3-5-sonnet with a system prompt setting it as data quality expert, user message passing anomaly type, affected columns, and statistics summary, requesting JSON output with classification (schema_drift/missing_data/outliers/upstream_failure), severity (low/medium/high/critical), confidence, and explanation. Then AI Remediation Planner Agent calls Claude again to generate a single remediation action (fill_nulls/cap_outliers/reformat_schema/retry_upstream) with parameters, success probability, and reasoning.

    Execution prompt · Source text。AI Anomaly Classifier Agent node options.system field

    You are a data quality expert specializing in anomaly detection and classification. Analyze data quality issues and provide accurate classifications with severity assessments.

    Execution prompt · Source text。AI Anomaly Classifier Agent node messages.values[0].content field

    =Analyze this data quality anomaly and classify it:
    
    Anomaly Type: {{ $('Run Statistical Quality Checks').first().json.anomalyType }}
    Affected Columns: {{ $('Run Statistical Quality Checks').first().json.affectedColumns }}
    Statistics: {{ JSON.stringify($('Run Statistical Quality Checks').first().json.statistics) }}
    Total Records: {{ $('Run Statistical Quality Checks').first().json.totalRecords }}
    
    Classify this anomaly into one of these categories:
    - schema_drift: Unexpected changes in data structure or types
    - missing_data: High rates of null or missing values
    - outliers: Statistical anomalies in numeric data
    - upstream_failure: Issues with data source or pipeline
    
    Provide your response as JSON with:
    {
      "classification": "category_name",
      "severity": "low|medium|high|critical",
      "confidence": 0-100,
      "explanation": "detailed reasoning"
    }

    Execution prompt · Source text。AI Remediation Planner Agent node options.system field

    You are a data engineering expert specializing in automated remediation strategies. Suggest practical, safe remediation actions for data quality issues based on anomaly classification and historical patterns.

    Execution prompt · Source text。AI Remediation Planner Agent node messages.values[0].content field

    =Based on this classified anomaly, suggest a specific remediation action:
    
    Classification: {{ $json.classification }}
    Severity: {{ $json.severity }}
    Anomaly Details: {{ $json.explanation }}
    Affected Columns: {{ $('Run Statistical Quality Checks').first().json.affectedColumns }}
    Statistics: {{ JSON.stringify($('Run Statistical Quality Checks').first().json.statistics) }}
    
    Suggest ONE of these remediation actions:
    - fill_nulls: Fill missing values with appropriate defaults
    - cap_outliers: Cap extreme values to acceptable ranges
    - reformat_schema: Fix schema mismatches or type issues
    - retry_upstream: Retry fetching data from source
    
    Provide:
    1. Action (one of the above)
    2. Parameters needed for the action
    3. Expected success probability (0-100)
    4. Reasoning
    
    Return as JSON: {"action": "...", "parameters": {...}, "successProbability": ..., "reasoning": "..."}
  4. Execute remediation action

    Query Remediation History from PostgreSQL queries last 30 days of similar anomaly remediation history; Calculate Remediation Success Rate computes historical success rates by action and attaches to remediation plan. Route by Remediation Type routes based on action field to one of four branches: Remediate Missing Values (median for numeric, mode for categorical), Remediate Outliers (IQR bound capping), Remediate Schema Format (convert to expected schema types), Retry Upstream Data Fetch (placeholder, actual retry logic must be implemented). When severity is critical, Check If Critical Severity in parallel triggers Post Critical Alert to PagerDuty to create PagerDuty incident.

  5. Validate remediation and notify

    Merge Remediated Data Streams combines branch results; Re-run Quality Checks on Remediated Data re-runs null, outlier, and schema checks. If validation passes (remediationSuccessful=true), Send Success Notification to Slack sends success notification; otherwise Escalate to Human Review in Slack sends human review request with data samples and statistics, triggering Prepare Data Sample for Review to generate representative samples.

  6. Log incident and update monitoring

    Log Successful/Failed Remediation Incident writes results to PostgreSQL incident table; Aggregate Incident Logs aggregates; Generate Remediation Report produces comprehensive report with success rates, breakdowns by type/severity/action, top issues, recommendations; Send Metrics to DataDog pushes anomaly count, remediation success rate, health score; Update Historical Baseline Metrics updates baseline table.

Prompt you can copy

Setup guidance · Editorial suggestion。Give to setup assistant to confirm inputs and permissions, then replace placeholders and test

This block is the prompt. Ads are never placed here.

Please set up this n8n template for a self-healing data pipeline. First confirm you have: n8n instance, PostgreSQL (source table + incident table + baseline table), Anthropic Claude API key, Slack channel permissions, PagerDuty service ID and API key, DataDog API key. After importing the template, replace all placeholders step by step, test individual node execution, then enable the schedule trigger.

Template has 46 nodes; core modifications are in Set Pipeline Parameters and PostgreSQL query table/column names

Source

Detect and self-heal data pipeline incidents with PostgreSQL, Claude and Slack · rnair1996 · n8n.io · 2026-08-29

Comments & feedback

Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.

Loading…

    Related