SQL Data Quality & Anomaly Checks
Catch broken joins, time-window mistakes, and outliers before they derail your analysis.
Prompt Overview
Tips For You
Always run anti-joins to find orphans after big joins. | Check the first and last timestamps to confirm the window. | Quantify acceptable null rates per column. | Keep checks fast and sargable for large tables. | Document Go/No-Go rules next to the dashboard.
From Operations TeamNexusAi TechnologyProblem It Solves
Prevents false insights from null explosions, double counts, and bad time handling.
Pre-publish gate
Enforces a quality bar before dashboards update.
Targeted SQL snippets
Copy/paste checks for joins, coverage, and nulls.
Threshold templates
Defines acceptable error bands and alerts.
Anomaly triage
Tells you who to engage and what to test next.
AI Prompt Instructions
Act as: Data Quality Analyst and reliability gatekeeper.
Why this task matters: Even good queries can produce misleading results if joins double-count, time zones drift, or NULL rules are unclear. Systematic checks save reputation and time.
Important boundaries:
- No destructive SQL. Focus on validation queries and diagnostics.
- Assume large datasets; prefer scalable checks.
User inputs:
- Primary SQL query and purpose
- Relevant table schemas and keys
- Expected grain and time window
- Known edge cases (late events, soft deletes)
Objectives:
1) Identify top data risks and propose targeted validation queries.
2) Detect counting inflation, missing data windows, and timezone drift.
3) Provide go/no-go criteria for publishing results.
Analysis workflow:
1) Restate the intended grain and metric.
2) Generate validation SQL snippets: row counts by key, anti-joins for orphan keys, null distributions, duplicate checks, time coverage heatmap.
3) Propose sample-size sanity checks and expected ranges.
4) Provide a short anomaly triage plan.
Required output format:
- Risk summary (bullets)
- Validation snippets (SQL blocks with comments)
- Expected ranges and thresholds
- Triage steps (who/what/when)
- Go/No-Go checklist
Quality controls:
- Avoid SELECT *; label each check and expected outcome.
- Use indexed predicates and time filters for performance.
Verification checklist:
- Do counts match at each join boundary?
- Are time windows aligned across tables?
Final instruction: Return the full package. If inputs are incomplete, ask 3–5 targeted questions, then propose conservative checks.
Expected Outcome
Risk summary: - Potential double-count via orders×order_items join - Missing late events from 00:00–01:00 UTC Validation snippets: -- Duplicate orders by id SELECT order_id, COUNT(*) c FROM orders GROUP BY 1 HAVING COUNT(*)>1; -- Orphan items SELECT oi.order_id FROM order_items oi LEFT JOIN orders o ON oi.order_id=o.id WHERE o.id IS NULL; -- Coverage by hour (UTC) SELECT DATE_TRUNC('hour', created_at) h, COUNT(*) FROM events WHERE created_at>=NOW()-INTERVAL '3 days' GROUP BY 1 ORDER BY 1; Thresholds: orphan items <0.1%; hour buckets non-zero across business hours Go/No-Go: publish only if all thresholds pass.
Implementation Journey
Generate checks
In ChatGPT, paste your main query, schemas, and grain. Request validation snippets and thresholds using this prompt. Expect labeled SQL checks and a Go/No-Go list.
7 minPattern sanity pass
Paste the same inputs into Gemini to spot time-window drift and duplicate patterns. Expect a short list of likely pitfalls to test next.
6 minRun and gate
Execute the validation SQL in your warehouse, paste results back into ChatGPT, and apply the Go/No-Go checklist before publishing any charts.
12 min
