Schedule icon
Webhook icon
WorkingDirectory icon
Clone icon
Commands icon
Docker icon
Script icon
If icon
SlackIncomingWebhook icon
Log icon

Automate dbt Anomaly Detection and Slack Triage with Elementary

Orchestrate dbt Core and Elementary tests in Kestra. Catch volume, freshness, and schema anomalies, generate reports, and alert Slack.

Categories
Data

Silent data corruption, sudden row count drops, and breaking schema changes can cascade through business intelligence dashboards unnoticed until stakeholders complain. This blueprint orchestrates Elementary, the open-source data observability and testing framework for dbt, directly inside Kestra. It monitors data models for volume deviations, column distribution anomalies, and freshness violations, compiles an interactive HTML health report, and routes actionable triage notifications to Slack.

How it works

  1. A daily Schedule trigger (daily_morning_audit) launches the audit before morning reporting hours, while an authenticated Webhook trigger (upstream_warehouse_sync) enables upstream ingestion tools (such as Fivetran or Airbyte) to trigger checks upon data sync completion.
  2. A WorkingDirectory task (dbt_and_elementary_workspace) provisions a shared local filesystem for all test operations:
    • clone_repository (io.kestra.plugin.git.Clone) pulls the latest dbt models, configuration files, and packages.yml.
    • run_dbt_and_elementary (io.kestra.plugin.scripts.shell.Commands) spins up an isolated Docker container with dbt-postgres and elementary-data, generates an inline profile connecting to your data warehouse via secrets, installs required dbt packages (dbt deps), and executes Elementary tests (dbt test --select tag:elementary). It then runs edr report to build a self-contained HTML observability dashboard.
    • parse_elementary_results (io.kestra.plugin.scripts.python.Script) parses the compiled dbt test manifest and run results, outputting the total test count, detected anomaly count, and individual failure messages to Kestra variables.
  3. An If conditional task (evaluate_anomalies) routes downstream execution:
    • If anomalies are detected (has_anomalies: true), notify_slack_anomalies (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) sends a structured Slack Block Kit message with the failing test identifiers and error descriptions.
    • If no anomalies are detected, log_clean_run records a confirmation log.
  4. An errors block intercepts fatal runner aborts or network dropouts, ensuring that pipeline infrastructure failures are never silent.

What you get

  • Automated anomaly detection across table row counts, null rates, and column value distributions without writing custom SQL tests.
  • An isolated, containerized runtime preventing local package dependency conflicts.
  • A standalone elementary_report.html artifact capturing table lineages and historical test run timelines.
  • Formatted Slack alert cards directing analytics engineers straight to the offending dbt model and execution trace.

Who it's for

  • Analytics Engineers responsible for production dbt transformation reliability.
  • Data Platform Engineers building automated data quality gates and observability pipelines.
  • Data Operations teams requiring automated incident triage before morning BI refreshes.

Why orchestrate this with Kestra

Elementary provides tests and reporting, but requires an external orchestrator to schedule runs, manage database secrets securely, handle retries, and route alerts. Kestra provides a containerized task runner, declarative Git-versioned flow definitions, unified secret masking ({{ secret(...) }}), and event-driven webhook triggers. If a runner crashes or database connectivity drops, Kestra's execution state engine captures logs and executes the errors safeguard.

Prerequisites

  • A Kestra worker with Docker enabled to execute containerized dbt and Elementary tasks.
  • A dbt project configured with the elementary-data/elementary package in packages.yml.
  • A target data warehouse (PostgreSQL, Snowflake, BigQuery, or Redshift) with read and write permissions to the Elementary metadata schema.

Secrets

Configure the following secrets in your Kestra namespace:

  • POSTGRES_HOST: Hostname of the target data warehouse.
  • POSTGRES_PORT: Port number of the warehouse (default 5432).
  • POSTGRES_DB: Name of the target database.
  • POSTGRES_USER: Database user authorized to execute transformations and write Elementary artifacts.
  • POSTGRES_PASSWORD: Database user password.
  • POSTGRES_SCHEMA: Primary schema housing dbt models and Elementary tables.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL for incident triage alerting.
  • WEBHOOK_KEY: Authentication key for triggering the pipeline via HTTP Webhook.

Quick start

  1. Configure the required database and Slack secrets in your Kestra namespace settings.
  2. Import this blueprint into your Kestra instance.
  3. Click Execute with the default inputs to test connection and run initial validation.
  4. Inspect the execution logs to verify that dbt deps and Elementary test suites complete cleanly.
  5. Enable the daily_morning_audit schedule trigger to activate automated morning audits.

How to extend

  • Swap the dbt-postgres adapter in run_dbt_and_elementary for dbt-snowflake, dbt-bigquery, or dbt-redshift to match your cloud data warehouse.
  • Upload the generated elementary_report.html to an Amazon S3 or Google Cloud Storage bucket with a presigned URL using io.kestra.plugin.aws.s3.Upload.
  • Add automated Jira or PagerDuty incident creation using Kestra's notification plugins when high-severity anomalies occur.
  • Connect downstream BI cache warming flows (such as Tableau or Looker refresh APIs) to execute only when evaluate_anomalies passes cleanly.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.