Script icon
ChatCompletion icon
SlackIncomingWebhook icon

Explain Workflow Failures with OpenAI and Send Insights to Slack

Turn cryptic Kestra failure logs into plain-English explanations with OpenAI and post them to Slack, cutting mean time to resolution for data and platform teams.

Categories
AICoreInfrastructure

Stack traces tell you what broke, rarely why. This blueprint wires an OpenAI Large Language Model into Kestra's error handling so that whenever a task fails, the model reads the real error logs, explains the likely cause in plain language, and pushes that explanation straight to Slack. Engineers open the alert and already know what went wrong, no log spelunking required. It is a practical pattern for AI-assisted observability, automated debugging, and faster incident response.

How it works

  1. The bad_python_task task (io.kestra.plugin.scripts.python.Script) runs a Python snippet that intentionally fails, standing in for any real task that can error.
  2. When any task in the flow fails, Kestra runs the errors block instead of stopping silently.
  3. The ai task (io.kestra.plugin.openai.ChatCompletion) sends the failure context to the gpt-4o model, passing the captured logs via {{ errorLogs() }} in its prompt. The prompt instructs the model to reply in clean plain text with no Markdown so the output renders cleanly downstream.
  4. The alert task (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) posts a message that names the failed flow and execution and embeds the AI explanation read from {{ outputs.ai.choices[0].message.content }}.

What you get

  • Plain-English root-cause hints attached to every failure alert.
  • Slack notifications enriched with AI insight, not just raw stack traces.
  • Lower mean time to resolution (MTTR) for on-call engineers.
  • A reusable error handler you can drop into any flow.

Who it's for

  • Platform and DevOps engineers running production pipelines.
  • Data teams who want failures triaged before anyone opens a log.
  • On-call responders who need context fast.

Why orchestrate this with Kestra

Kestra's declarative YAML lets you attach this AI explanation step as a flow-level errors handler that fires automatically on failure, with no glue code. You get retries, full execution lineage, and event-driven triggers across every task. OpenAI's API has no scheduler, no error context, and no notion of your pipeline; Kestra supplies the failure event, the captured logs, and the delivery to Slack, turning a standalone model call into an operational safety net.

Prerequisites

  • A Kestra instance with the OpenAI and Slack plugins available.
  • An OpenAI API key with access to gpt-4o.
  • A Slack incoming webhook URL pointing at your alert channel.

Secrets

  • OPENAI_API_KEY: API key used by the ChatCompletion task.
  • SLACK_WEBHOOK_URL: incoming webhook URL used by the Slack task.

Quick start

  1. Add the OPENAI_API_KEY and SLACK_WEBHOOK_URL secrets to your Kestra instance.
  2. Import this blueprint into a namespace.
  3. Run it. The Python task fails on purpose, triggering the errors block.
  4. Check your Slack channel for the AI-generated failure explanation.

How to extend

  • Replace bad_python_task with your real tasks and reuse the errors block as-is.
  • Swap gpt-4o for another model, or tune the prompt to request remediation steps or severity scoring.
  • Route alerts to PagerDuty, email, or a ticketing system instead of (or alongside) Slack.
  • Move the handler into a shared flow and call it from many pipelines.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.