Generate dbt Validation SQL Notebooks
This skill generates a Monte Carlo SQL Notebook of validation queries for dbt model changes, from a GitHub PR or local repo, opening directly as an import URL.
14.1.0Add to Favorites
Why it matters
Automate the validation of dbt model and snapshot changes by generating interactive SQL Notebooks. This skill ensures data integrity by creating queries that compare changes against production or development databases.
Outcomes
What it gets done
Generate SQL validation queries for dbt changes from GitHub PRs or local repositories.
Automatically infer schema and database parameters for validation queries.
Create importable SQL Notebook URLs for direct use in the Monte Carlo interface.
Support both single-database analysis and before/after comparison queries.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-monte-carlo-validation-notebook | bash Overview
Setup
This skill generates a Monte Carlo SQL Notebook of validation queries (row counts, uniqueness, NULL rates, before/after comparisons) for changed dbt models, sourced from a GitHub PR or local repo, and opens it as a ready-to-run import URL. Use it to validate dbt model or snapshot changes in a PR or local branch before merging. It only analyzes changed .sql files under models/ or snapshots/ - it reports and stops if no model files changed.
What it does
This skill generates a Monte Carlo SQL Notebook containing validation queries for dbt model or snapshot changes, sourced from either a GitHub PR URL or a local dbt repository (auto-detected from the target argument), and outputs it as a browser-openable import URL (<MC_BASE_URL>/notebooks/import#<base64-encoded-yaml>). It requires the GitHub CLI (gh, authenticated) for PR mode, Python 3 with pyyaml, and works best invoked with /model sonnet for faster generation.
The workflow runs in six phases: Phase 1 fetches changed .sql files under models//snapshots/ (via gh pr view/gh pr diff for PR mode, or git diff against the detected base branch for local mode), plus dbt_project.yml for schema resolution, filtered to at most 10 models unless the caller specifies a --models list; Phase 2 parses each changed model's metadata, diff, and classifies it as NEW or MODIFIED; Phase 3 generates validation queries per classification - NEW models get row-count, sample-data-preview, segmentation-count, uniqueness-check, NULL-rate, and time-axis-continuity queries, while MODIFIED models additionally get changed-field-distribution and before/after comparison queries between {{prod_db}} and {{dev_db}}; Phase 4 assembles the notebook YAML (metadata, parameter cells for prod_db/dev_db database selection, a markdown summary cell, and SQL cells organized by model); Phase 5 encodes it into an import URL; Phase 6 presents a summary and opens the notebook.
cells:
- id: param-prod-db
type: parameter
content:
name: prod_db
config: { type: text, default_value: "ANALYTICS", placeholder: "Prod database" }
Generated SQL uses ANSI-compatible syntax working across Snowflake, BigQuery, Redshift, and Athena, with minor adjustments possibly needed for warehouse-specific quirks. Two helper scripts support the flow: resolve_dbt_schema.py (resolves each model's output schema from dbt_project.yml routing rules and model config overrides) and generate_notebook_url.py (encodes the notebook YAML and opens it in the browser).
When to use - and when NOT to
Use it to validate dbt model or snapshot changes before or after merging - reviewing a PR's changed models, or comparing dev vs. prod state for a local branch's changes - by generating targeted before/after and data-quality queries rather than writing them by hand. It is scoped to changed .sql files under models//snapshots/ directories; non-model changes are not analyzed, and if no model SQL files changed, the skill reports that and stops rather than generating an empty or irrelevant notebook.
Inputs and outputs
Input is a GitHub PR URL or a local dbt repo path, with optional --mc-base-url and --models filters. Output is a Monte Carlo SQL Notebook import URL containing parameterized validation queries (row counts, uniqueness, NULL rates, segmentation, and before/after comparisons) for each changed model, ready to open and run interactively in the MC Bridge SQL Notebook interface.
Integrations
Uses the GitHub CLI (gh) for PR metadata/diffs/file content, git for local-mode diffs, Python/pyyaml for notebook YAML construction, and targets Monte Carlo's SQL Notebook interface with ANSI-compatible SQL portable across Snowflake, BigQuery, Redshift, and Athena.
Who it's for
Data/analytics engineers reviewing dbt model changes (in a PR or locally) who want an automatically generated, ready-to-run set of validation queries comparing before/after state rather than writing ad hoc SQL checks by hand.
FAQ
Common questions
Discussion
Questions & comments ยท 0
Sign In Sign in to leave a comment.