Prompt
How do I set up an ETL assistant for detecting data issues in warehouse tables?
Latest observation
To set up an ETL assistant for detecting data issues in warehouse tables, think of it as a data quality monitoring assistant with three parts:
- Ingest metadata and table data
- Run detection rules / anomaly checks
- Report issues and route them to humans or workflows
Here’s a practical way to build it.
1) Define what “data issues” mean
Start by listing the kinds of problems you want the assistant to catch.
Common warehouse table issues:
- Missing values in required columns
- Duplicate rows or duplicate business keys
- Schema drift
- new columns
- removed columns
- type changes
- Unexpected null spikes
- Row count anomalies
- Freshness delays
- Invalid ranges
- negative amounts
- impossible dates
- Referential integrity breaks
- Distribution shifts
- today’s values look very different from historical values
- Late-arriving data
- Broken joins / orphan records
If you don’t define this clearly, the assistant will be noisy.
2) Gather the inputs the assistant needs
Your assistant should have access to:
A. Warehouse metadata
For each table:
- table name
- schema
- column names and types
- primary keys / unique keys
- freshness expectations
- expected row volume
- source system
- owner / team
B. Data profiling stats
For each table/column:
- row counts
- null counts
- distinct counts
- min/max
- mean/stddev for numeric columns
- top values
- percentage changes vs historical baseline
C. Historical baselines
Keep a time series of:
- daily row counts
- daily null rates
- daily distinct counts
- distribution metrics per column
This lets the assistant detect anomalies instead of only hard-coded rules.
3) Choose the detection approach
Usually you want a mix of:
Rule-based checks
Good for deterministic issues:
column is not nullamount >= 0status in (...)row_count > 0updated_at within last 24h
Statistical/anomaly checks
Good for unknown issues:
- row count deviates by > X standard deviations
- null rate spikes relative to baseline
- value distribution shifts significantly
- sudden increase in duplicates
Semantic/LLM-assisted interpretation
An LLM can help:
- explain the likely cause of an anomaly
- summarize affected tables
- suggest next debugging steps
- create a human-readable incident report
Important: let the LLM explain issues, not be the only detector.
4) Build the pipeline
A simple architecture:
Step 1: Metadata sync
Pull table schemas and ownership info from the warehouse catalog or information schema.
Step 2: Profiling job
Run scheduled SQL queries to compute quality metrics.
Example metrics per table:
- total rows
- rows loaded today
- null percentage per required column
- duplicates by key
- freshness lag
- min/max timestamps
Step 3: Check execution
Evaluate rules and anomaly thresholds.
Step 4: Issue classification
Classify findings:
- Critical
- Warning
- Informational
Step 5: Assistant response generation
The assistant converts raw metrics into:
- summary
- suspected root cause
- impacted downstream tables
- recommended action
Step 6: Alerting and ticketing
Send results to:
- Slack / Teams
- Jira / ServiceNow
- data observability dashboard
5) Create a table-level quality schema
For each table, define checks like this:
table: sales_orders
owner: analytics-team
freshness_sla_hours: 2
checks:
- type: not_null
columns: [order_id, customer_id, order_date]
- type: unique
columns: [order_id]
- type: accepted_values
column: order_status
values: [placed, shipped, delivered, cancelled]
- type: range
column: total_amount
min: 0
- type: freshness
timestamp_column: updated_at
- type: row_count_anomaly
baseline_days: 14
tolerance: 3
This makes the checks versioned and auditable.
6) Use SQL for most checks
Most warehouse quality checks can be done with SQL.
Examples:
Null rate
SELECT
COUNT(*) AS total_rows,
SUM(CASE WHEN customer_id IS NULL THEN 1 ELSE 0 END) AS null_customer_id,
1.0 * SUM(CASE WHEN customer_id IS NULL THEN 1 ELSE 0 END) / COUNT(*) AS null_rate
FROM sales_orders;
Duplicate keys
SELECT order_id, COUNT(*) AS cnt
FROM sales_orders
GROUP BY order_id
HAVING COUNT(*) > 1;
Freshness
SELECT MAX(updated_at) AS latest_update
FROM sales_orders;
Row count anomaly
SELECT
CURRENT_DATE AS run_date,
COUNT(*) AS row_count
FROM sales_orders
WHERE DATE(updated_at) = CURRENT_DATE;
Then compare against historical patterns.
7) Add an LLM layer for natural-language reasoning
The assistant can ingest:
- table metadata
- check results
- recent changes in pipeline runs
- owner info
- past incidents
And produce outputs like:
- “
sales_ordersfailed freshness SLA by 6 hours” - “Null rate in
customer_idincreased from 0.2% to 8.7%” - “Likely upstream issue in
orders_ingestionjob” - “Related downstream tables may be impacted:
fct_revenue,customer_360”
Use the LLM for:
- summarization
- explanation
- prioritization
- incident drafts
Do not use it as the only source of truth for numeric checks.
8) Set up an event loop or scheduler
Run the assistant on:
- every pipeline completion
- hourly for critical tables
- daily for batch facts
- on schema change events
Common tools:
- Airflow
- Dagster
- Prefect
- dbt + tests + custom monitoring
- cloud-native schedulers
9) Keep a feedback loop
You’ll want the assistant to improve over time.
Store:
- true positive / false positive labels
- whether alerts were acknowledged
- incident resolution notes
- which checks were useful
Then adjust:
- thresholds
- severity levels
- table-specific rules
- anomaly models
10) Recommended implementation stack
A simple stack could look like:
- Warehouse: Snowflake / BigQuery / Redshift / Databricks SQL
- Orchestration: Airflow / Dagster / Prefect
- Quality checks: dbt tests, Great Expectations, Soda, custom SQL
- Metadata store: Postgres / warehouse schema / catalog
- LLM layer: OpenAI API or similar
- Alerting: Slack + Jira
- Dashboard: Metabase / Grafana / Looker / custom UI
11) Minimal architecture example
A practical setup:
- Nightly job runs SQL checks on all critical warehouse tables
- Metrics are stored in
data_quality_metrics - An anomaly detector compares today vs historical baseline
- If thresholds are crossed, an incident record is created
- LLM generates a concise summary and next steps
- Slack alert is posted to the table owner channel
12) Example assistant output
A good assistant response might look like:
Issue detected in
sales_orders
- Freshness SLA breached: latest update is 7.2 hours old, threshold is 2 hours
- Null rate in
customer_idrose from 0.3% to 6.8%- Duplicate
order_idcount increased from 0 to 142Likely cause: upstream ingestion job
orders_stream_loaderfailed partially after 02:00 UTCRecommended actions:
- Check ingestion logs for failed partitions
- Re-run failed batch
- Validate downstream tables
fct_ordersandrevenue_daily
13) Best practices
- Start with high-value tables first
- Keep checks versioned in code
- Separate hard failures from warnings
- Avoid alert fatigue with deduplication and suppression windows
- Keep historical metrics for trend analysis
- Make ownership explicit for each table
- Validate changes after schema updates
14) If you want to use an LLM specifically
A good LLM prompt structure is:
- Role: data quality assistant
- Context: warehouse name, table metadata, recent job runs
- Inputs: check results, baseline stats, incident history
- Task: summarize issues, rank severity, suggest likely causes, recommend next steps
- Constraints: do not invent numbers; only use provided metrics
If you want, I can also provide:
- a reference architecture diagram,
- a dbt/Great Expectations implementation, or
- a sample Python ETL assistant script that checks warehouse tables and generates alerts.