dbt-investigator
Enables AI clients to automatically investigate dbt test failures, trace root cause through BigQuery lineage, and generate plain-English incident reports.
README
Data Quality Agent
An agentic AI system that automatically investigates dbt test failures, traces the root cause through BigQuery lineage, and generates a plain-English incident report โ cutting investigation time from hours to minutes.
๐ Architecture diagram ยท ๐ Sample incident report
Architecture
What it does
When a dbt test fails you normally get a cryptic error message. This agent:
- Fetches the failing rows from BigQuery โ sees the actual bad data
- Reads the dbt manifest โ understands the full lineage graph
- Traces upstream โ profiles columns in parent models and source tables
- Identifies the root cause โ finds where the bad data entered the pipeline
- Writes an incident report โ plain-English root cause, lineage trace, recommended fix, severity
not_null_fct_transactions_merchant failed (23 rows)
โ
โผ
Agent fetches failing rows โ reads fct lineage โ traces to int_ โ traces to stg_ โ checks raw source
โ
โผ
Root cause: 23 rows in raw.bank_transactions have NULL narration.
Merchant extraction returns NULL when narration is NULL.
Fix: Add COALESCE(narration, '') in stg_bank__transactions.
Severity: HIGH
Three trigger modes
1 โ CLI
python agent.py \
--test not_null_fct_transactions_merchant \
--model fct_transactions \
--column merchant \
--verbose
2 โ Webhook (Airflow or any HTTP caller)
python server.py # starts on port 5051
curl -X POST http://localhost:5051/investigate \
-H "Content-Type: application/json" \
-d '{"test_name": "not_null_fct_transactions_merchant", "model": "fct_transactions", "column": "merchant"}'
Point your Airflow DAG's on_failure_callback at this endpoint.
3 โ MCP (any AI client)
The MCP server exposes three tools to any MCP-compatible client โ Claude Code, OpenClaw (ChatGPT / Gemini / any client), Cursor, Zed:
| Tool | What it does |
|---|---|
investigate_failure |
Full agentic investigation โ incident report |
list_failures |
List failing tests from run_results.json |
get_report |
Read a saved incident report |
Claude Code:
claude mcp add -s user \
-e GCP_PROJECT=your-project \
-e BQ_LOCATION=asia-south1 \
-e DBT_MANIFEST_PATH=/path/to/dbt_bank/target/manifest.json \
-e DBT_RUN_RESULTS_PATH=/path/to/dbt_bank/target/run_results.json \
-e GEMINI_API_KEY=your-key \
dbt-investigator \
-- /path/to/venv/bin/python /path/to/mcp_server.py
OpenClaw (ChatGPT, Gemini, or any other client):
openclaw mcp set dbt-investigator '{
"command": "/path/to/venv/bin/python",
"args": ["/path/to/mcp_server.py"],
"cwd": "/path/to/data-quality-agent",
"env": {
"GCP_PROJECT": "your-project",
"GEMINI_API_KEY": "your-key",
"DBT_MANIFEST_PATH": "/path/to/manifest.json",
"DBT_RUN_RESULTS_PATH": "/path/to/run_results.json"
}
}'
openclaw mcp probe # โ dbt-investigator: 3 tools โ
Agent tools
| Tool | What the agent calls |
|---|---|
get_failing_rows |
Queries BigQuery for actual bad rows |
get_model_lineage |
Reads manifest.json for upstream/downstream |
get_model_sql |
Gets compiled SQL for any model |
get_column_profile |
null count, distinct count, min, max |
run_query |
Custom read-only BQ investigation |
get_source_freshness |
Checks staleness of source tables |
write_report |
Writes the final incident report |
Safety wall: all BigQuery queries are read-only (SELECT/WITH only). DML/DDL rejected before execution.
Setup
git clone https://github.com/ARAVINDHRAJA123/data-quality-agent.git
cd data-quality-agent
python3 -m venv venv && source venv/bin/activate
pip install -r requirements.txt
# Auth
gcloud auth application-default login
# Set environment
export GCP_PROJECT=your-project
export BQ_LOCATION=asia-south1
export DBT_MANIFEST_PATH=/path/to/dbt_bank/target/manifest.json
export DBT_RUN_RESULTS_PATH=/path/to/dbt_bank/target/run_results.json
# LLM (pick one)
export GEMINI_API_KEY=your-key # free
export ANTHROPIC_API_KEY=your-key # paid
Generate the manifest first (from your dbt project):
cd /path/to/dbt_project && dbt compile
# manifest.json is now at target/manifest.json
Stack
- Claude / Gemini โ LLM provider (auto-detected, free Gemini supported)
- BigQuery โ data warehouse (GCP)
- dbt manifest.json โ lineage graph and compiled SQL
- FastMCP โ MCP server (any AI client)
- Flask โ webhook server (Airflow integration)
- pytest โ test suite
Project structure
data-quality-agent/
โโโ agent.py โ agentic investigation loop (Claude + Gemini)
โโโ server.py โ Flask webhook server
โโโ mcp_server.py โ FastMCP server (any MCP client)
โโโ report.py โ incident report formatter
โโโ tools/
โ โโโ bq_tools.py โ BigQuery: failing rows, queries, freshness
โ โโโ dbt_tools.py โ manifest: lineage, SQL, test results
โโโ tests/
โ โโโ test_tools.py โ 11 unit tests (no BQ/LLM needed)
โโโ reports/ โ saved incident reports (markdown)
โโโ requirements.txt
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.