Mine pharma complaint trends and trigger CAPA alerts with Claude and Slack

Go to Workflow
0 views
Built by Oneclick AI Squad Oneclick AI Squad
Created on September 03, 2026

Description

Quick overview
This workflow polls a complaint-source API on a schedule, uses Anthropic Claude to extract structured defect signals from complaint narratives, clusters complaints by product and defect category, detects statistically unusual spikes against a rolling baseline, and escalates anomalies by creating a CAPA ticket and sending a Slack alert.

How it works
Runs on a schedule (or manually) to start a new complaint-mining cycle.
Fetches recently logged complaints from a complaint system API and removes complaints already processed using workflow static data.
If no new complaints are found, ends the run without calling Anthropic.
Sends each new complaint narrative to an Anthropic Claude agent to extract product, batch/lot, defect category, and severity, and falls back to safe defaults if parsing fails.
Aggregates extracted complaints into clusters keyed by product and defect category, then compares each cluster’s volume to its rolling historical mean using a z-score and updates the stored baseline.
For clusters flagged as statistical anomalies, creates a CAPA escalation via an HTTP API and posts an alert to a Slack channel.
Logs every cluster (escalated and non-escalated) to a trend-store API for ongoing tracking.

Setup
Configure HTTP Header Auth credentials for the complaint-source API, CAPA ticketing API, and trend-store API used by the three HTTP Request steps.
Add an Anthropic (Claude) API credential/connection for the AI Agent’s language model.
Add a Slack credential and ensure the target channels exist (for example, the default #quality-capa-escalations).
Update the endpoint URLs, Slack channel names, and the z-score/baseline settings in the configuration step to match your systems and desired sensitivity.

Nodes Used (5)

AI Agent
@n8n/n8n-nodes-langchain.agent
Anthropic Chat Model
@n8n/n8n-nodes-langchain.lmChatAnthropic
Code
n8n-nodes-base.code
HTTP Request
n8n-nodes-base.httpRequest
Slack
n8n-nodes-base.slack