Schedule icon
Query icon
ChatCompletion icon
Script icon
Docker icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon

AI Customer Churn Probability Detector

Queries inactive CRM accounts, evaluates churn probability using Anthropic Claude, and dispatches high-urgency retention alerts to Slack.

Categories
AIBusiness

Customer churn is one of the most critical threats to recurring-revenue software companies. When customer telemetry signals decline, such as daily active logins dropping off, support ticket backlogs lingering, or core feature usage stalling, traditional heuristics often flag accounts only after cancellation notices are submitted.

By orchestrating database telemetry queries alongside Anthropic Claude, revenue teams can synthesize multidimensional product signals into nuanced churn risk assessments with tailored retention playbooks.

This blueprint automates weekly customer retention audits: it pulls inactive accounts from PostgreSQL, prompts Claude to compute an objective churn risk score (0-100) and draft account-specific outreach recommendations, and routes high-priority churn alerts to Customer Success teams via Slack.

How it works

  1. Weekly Scheduled Scan: The weekly_churn_scan trigger (io.kestra.plugin.core.trigger.Schedule) executes every Monday at 09:00 UTC.
  2. CRM Database Query: The query_inactive_accounts task (io.kestra.plugin.jdbc.postgresql.Query) pulls top-MRR customer accounts with inactivity exceeding inactive_days_threshold.
  3. Claude Churn Scoring: The analyze_churn_risk_with_claude task (io.kestra.plugin.anthropic.ChatCompletion) sends account telemetry to Claude to score churn drivers and formulate retention actions.
  4. Python Score Parsing: The parse_churn_scores task (io.kestra.plugin.scripts.python.Script) extracts accounts exceeding churn_risk_score_alert_threshold and compiles churn_analysis_report.json.
  5. Condition Branching: The evaluate_high_risk_condition flowable task (io.kestra.plugin.core.flow.If) branches based on whether any high-risk accounts were discovered.
  6. Slack Alert Dispatch: When risk is flagged, alert_customer_success_high_churn (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) delivers an actionable retention card.
  7. Audit Manifest: The export_churn_manifest task records execution state for revenue operations dashboards.

Architecture diagram

flowchart TD
    A[Schedule: Weekly Monday 09:00 UTC] --> B[query_inactive_accounts: PostgreSQL]
    B --> C[analyze_churn_risk_with_claude: Anthropic Claude]
    C --> D[parse_churn_scores: Python Score Parser]
    D --> E{High Churn Risk Detected?}
    E -- Yes --> F[alert_customer_success_high_churn: Slack]
    E -- No --> G[log_churn_status_healthy: Log]
    F --> H[export_churn_manifest: Return JSON]
    G --> H

Use cases

  • Proactive Churn Prevention: Identify enterprise accounts with declining product usage weeks before renewal discussions.
  • Automated RevOps Telemetry Analysis: Combine database usage metrics with generative AI reasoning to score account health.
  • Customer Success Workflow Automation: Instantly equip customer success managers with tailored outreach playbooks on Slack.

What you get

  • Automated discovery of dormant high-MRR customer accounts before contract expiration.
  • AI-generated churn risk scores (0-100) and root-cause driver explanations.
  • Tailored account executive outreach recommendations generated by Claude.
  • Structured Slack notifications formatted for immediate Customer Success follow-up.

Who it is for

  • Customer Success Managers responsible for account retention and Net Revenue Retention (NRR).
  • Revenue Operations (RevOps) teams automating proactive churn intervention.
  • Product Managers tracking feature abandonment across customer cohorts.

Why orchestrate this with Kestra

Building custom retention models requires setting up ETL jobs, embedding inference APIs, and maintaining notification channels. Kestra combines database querying, Anthropic LLM inference, Python parsing, and Slack alerting into a clean, maintainable workflow.

Inputs

Name Type Default Description
postgres_url STRING jdbc:postgresql://... JDBC URL of CRM database.
postgres_username STRING crm_reader Read-only database user.
inactive_days_threshold INT 30 Inactivity window before evaluation.
churn_risk_score_alert_threshold INT 75 Minimum risk score to trigger alert.
slack_channel STRING #customer-success Slack channel destination for alerts.

Expected outputs

  • {{ outputs.parse_churn_scores.vars.high_risk_detected }}: Boolean flag indicating if high-risk accounts exist.
  • {{ outputs.parse_churn_scores.vars.top_risk_company }}: Company name of top at-risk account.
  • {{ outputs.parse_churn_scores.vars.top_risk_score }}: Numerical churn score of top offender.
  • {{ outputs.parse_churn_scores.outputFiles['churn_analysis_report.json'] }}: Complete JSON diagnostic report.

Prerequisites

  • PostgreSQL CRM database containing a customer accounts table.
  • Anthropic API key stored in Kestra secrets.
  • Slack Incoming Webhook configured for Customer Success alerts.

Secrets

  • POSTGRES_PASSWORD: Password for the PostgreSQL database user.
  • ANTHROPIC_API_KEY: API key for Anthropic Claude inference.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook endpoint URL.

Quick start

  1. Configure POSTGRES_PASSWORD, ANTHROPIC_API_KEY, and SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Import this flow YAML into your Kestra instance.
  3. Click Execute in the UI to perform an initial retention scan.
  4. Review execution outputs to inspect generated risk scores and outreach tactics.

Common pitfalls and troubleshooting

  • Token Limits: When evaluating dozens of accounts, restrict batch size (e.g. LIMIT 10) to keep token usage within API rate limits.
  • Date Intervals: In PostgreSQL, ensure last_active_date is indexed to prevent full-table scans during the query step.
  • JSON Parsing: Claude is instructed to return strict JSON; the script safely handles and strips any surrounding markdown code fences.

How to extend

  • Add io.kestra.plugin.hubspot.DealUpdate to automatically create high-urgency renewal risk tasks in your CRM.
  • Ingest Zendesk ticket sentiment via io.kestra.plugin.core.http.Request to enrich telemetry prior to LLM scoring.
  • Trigger personalized executive email drafts using io.kestra.plugin.notifications.mail.MailSend.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.