generate-validation-notebook
Generates SQL validation notebooks to verify dbt model changes before deployment.
Install
mkdir -p .claude/skills/generate-validation-notebook && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/11478" && unzip -o skill.zip -d .claude/skills/generate-validation-notebook && rm skill.zipInstalls to .claude/skills/generate-validation-notebook
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Generate SQL validation notebooks for dbt changes. Pass a GitHub PR URL or local dbt repo path.Key capabilities
- →Generate SQL validation queries for dbt changes.
- →Process GitHub PRs to identify changed dbt models.
- →Infer schema per model from `dbt_project.yml` and model configs.
- →Create a Monte Carlo Bridge SQL Notebook import URL.
How it works
The skill analyzes dbt changes from a GitHub PR or local repository, infers model schemas, and generates ANSI-compatible SQL validation queries. These queries are then packaged into a YAML structure and encoded into an import URL for the Monte Carlo Bridge SQL Notebook interface.
Inputs & outputs
When to use generate-validation-notebook
- →Generate validation queries for dbt models
- →Validate dbt schema changes from a PR
- →Export validation notebooks to web interface
About this skill
Tip: This skill works well with Sonnet. Run
/model sonnetbefore invoking for faster generation.
Generate a SQL Notebook with validation queries for dbt changes.
Arguments: $ARGUMENTS
Parse the arguments:
- Target (required): first argument — a GitHub PR URL or local dbt repo path
- MC Base URL (optional):
--mc-base-url <URL>— defaults tohttps://getmontecarlo.com - Models (optional):
--models <model1,model2,...>— comma-separated list of model filenames (without.sqlextension) to generate queries for. Only these models will be included. By default, all changed models are included up to a maximum of 10.
Setup
Prerequisites:
gh(GitHub CLI) — required for PR mode. Must be authenticated (gh auth status).python3— required for helper scripts.pyyaml— install withpip3 install pyyaml(orpip install pyyaml,uv pip install pyyaml, etc.)
Note: Generated SQL uses ANSI-compatible syntax that works across Snowflake, BigQuery, Redshift, and Athena. Minor adjustments may be needed for specific warehouse quirks.
This skill includes two helper scripts in ${CLAUDE_PLUGIN_ROOT}/skills/generate-validation-notebook/scripts/:
resolve_dbt_schema.py- Resolves dbt model output schemas fromdbt_project.ymlrouting rules and model config overrides.generate_notebook_url.py- Encodes notebook YAML into a base64 import URL and opens it in the browser.
Mode Detection
Auto-detect mode from the target argument:
- If target looks like a URL (contains
://orgithub.com) -> PR mode - If target is a path (
.,/path/to/repo, relative path) -> Local mode
Context
This command generates a SQL Notebook containing validation queries for dbt changes. The notebook can be opened in the MC Bridge SQL Notebook interface for interactive validation.
The output is an import URL that opens directly in the notebook interface:
<MC_BASE_URL>/notebooks/import#<base64-encoded-yaml>
Key Features:
- Database Parameters: Two
textparameters (prod_dbanddev_db) for selecting databases - Schema Inference: Automatically infers schema per model from
dbt_project.ymland model configs - Single-table queries: Basic validation queries using
{{prod_db}}.<SCHEMA>.<TABLE> - Comparison queries: Before/after queries comparing
{{prod_db}}vs{{dev_db}} - Flexible usage: Users can set both parameters to the same database for single-database analysis
Notebook YAML Spec Reference
Key structure:
version: 1
metadata:
id: string # kebab-case + random suffix
name: string # display name
created_at: string # ISO 8601
updated_at: string # ISO 8601
default_context: # optional database/schema context
database: string
schema: string
cells:
- id: string
type: sql | markdown | parameter
content: string # SQL, markdown, or parameter config (JSON)
display_type: table | bar | timeseries
Parameter Cell Spec
Parameter cells allow defining variables referenced in SQL via {{param_name}} syntax:
- id: param-prod-db
type: parameter
content:
name: prod_db # variable name
config:
type: text # free-form text input
default_value: "ANALYTICS"
placeholder: "Prod database"
display_type: table
Parameter types:
text: Free-form text input (used for database names)schema_selector: Two dropdowns (database -> schema), value stored asDATABASE.SCHEMAdropdown: Select from predefined options
Task
Generate a SQL Notebook with validation queries based on the mode and target.
Phase 1: Get Changed Files
The approach differs based on mode:
If PR mode (GitHub PR):
-
Extract the PR number and repo from the target URL.
- Example:
https://github.com/monte-carlo-data/dbt/pull/3386-> owner=monte-carlo-data, repo=dbt, PR=3386
- Example:
-
Fetch PR metadata using
gh:
gh pr view <PR#> --repo <owner>/<repo> --json number,title,author,mergedAt,headRefOid
- Fetch the list of changed files:
gh pr view <PR#> --repo <owner>/<repo> --json files --jq '.files[].path'
- Fetch the diff:
gh pr diff <PR#> --repo <owner>/<repo>
-
Filter the changed files list to only
.sqlfiles undermodels/orsnapshots/directories (at any depth — e.g.,models/,analytics/models/,dbt/models/). These are the dbt models to analyze. If no model SQL files were changed, report that and stop. -
For each changed model file, fetch the full file content at the head SHA:
gh api repos/<owner>/<repo>/contents/<file_path>?ref=<head_sha> --jq '.content' | python3 -c "import sys,base64; sys.stdout.write(base64.b64decode(sys.stdin.read()).decode())"
- Fetch dbt_project.yml for schema resolution. Detect the dbt project root by looking at the changed file paths — find the common parent directory that contains
dbt_project.yml. Try these paths in order until one succeeds:
gh api repos/<owner>/<repo>/contents/<dbt_root>/dbt_project.yml?ref=<head_sha> --jq '.content' | python3 -c "import sys,base64; sys.stdout.write(base64.b64decode(sys.stdin.read()).decode())"
Common <dbt_root> locations: analytics, . (repo root), dbt, transform. Try each until found.
Save dbt_project.yml to /tmp/validation_notebook_working/<PR#>/dbt_project.yml.
If Local mode (Local Directory):
-
Change to the target directory.
-
Get current branch info:
git rev-parse --abbrev-ref HEAD
-
Detect base branch - try
main,master,developin order, or use upstream tracking branch. -
Get the list of changed SQL files compared to base branch:
git diff --name-only <base_branch>...HEAD -- '*.sql'
-
Filter to only
.sqlfiles undermodels/orsnapshots/directories (at any depth — e.g.,models/,analytics/models/,dbt/models/). If no model SQL files were changed, report that and stop. -
Get the diff for each changed file:
git diff <base_branch>...HEAD -- <file_path>
-
Read model files directly from the filesystem.
-
Find dbt_project.yml:
find . -name "dbt_project.yml" -type f | head -1
- For notebook metadata in local mode, use:
- ID:
local-<branch-name>-<timestamp> - Title:
Local: <branch-name> - Author: Output of
git config user.name - Merged: "N/A (local)"
- ID:
Model Selection (applies to both modes)
After filtering to .sql files under models/ or snapshots/:
-
If
--modelswas specified: Filter the changed files list to only include models whose filename (without.sqlextension, case-insensitive) matches one of the specified model names. If any specified model is not found in the changed files, warn the user but continue with the models that were found. If none match, report that and stop. -
Model cap: If more than 10 models remain after filtering, select the first 10 (by file path order) and warn the user:
⚠️ <total_count> models changed — generating validation queries for the first 10 only. To generate for specific models, re-run with: --models <model1,model2,...> Skipped models: <list of skipped model filenames>
Phase 2: Parse Changed Models
For EACH changed dbt model .sql file, parse and extract:
2a. Model Metadata
Output table name -- Derive from file name:
<any_path>/models/<subdir>/<model_name>.sql-> table is<MODEL_NAME>(uppercase, taken from the filename)
Output schema -- Use the schema resolution script:
-
Setup: Save
dbt_project.ymland model files to/tmp/validation_notebook_working/<id>/preserving paths:/tmp/validation_notebook_working/<id>/ +-- dbt_project.yml +-- models/ +-- <path>/<model>.sql -
Run the script for each model:
python3 ${CLAUDE_PLUGIN_ROOT}/skills/generate-validation-notebook/scripts/resolve_dbt_schema.py /tmp/validation_notebook_working/<id>/dbt_project.yml /tmp/validation_notebook_working/<id>/models/<path>/<model>.sql -
Error handling: If the script fails, STOP immediately and report the error. Do NOT proceed with notebook generation if schema resolution fails.
-
Output: The script prints the resolved schema (e.g.,
PROD,PROD_STAGE,PROD_LINEAGE)
Note: Do NOT manually parse dbt_project.yml or model configs for schema -- always use the script. It handles model config overrides, dbt_project.yml routing rules, PROD_ prefix for custom schemas, and defaults to PROD.
Config block -- Look for {{ config(...) }} and extract:
materialized-- 'table', 'view', 'incremental', 'ephemeral'unique_key-- the dedup key (may be a string or list)cluster_by-- clustering fields (may contain the time axis)
Core segmentation fields -- Scan the entire model SQL for fields likely to be business keys:
- Fields named
*_id(e.g.,account_id,resource_id,monitor_id) that appear in JOIN ON, GROUP BY, PARTITION BY, orunique_key - Deduplicate and rank by frequency. Take the top 3.
Time axis field -- Detect the model's time dimension (in priority order):
is_incremental()block: field used in the WHERE comparisoncluster_byconfig: timestamp/date fields- Field name conventions:
ingest_ts,created_time,date_part,timestamp,run_start_time,export_ts,event_created_time - ORDER BY DESC in QUALIFY/ROW_NUMBER
If no time axis is found, skip time-axis queries for this model.
2b. Diff Analysis
Parse the diff hunks for this file. Classify each changed line:
- Changed fields -- Lines added/modified in SELECT clauses or CTE definitions. Extract the output column name.
- Changed filters -- Lines added/modified in WHERE clauses.
- Changed joins -- Lines added/modified in JOIN ON conditions.
- Changed unique_key -- If
unique_keyin config was modified, note both old
Content truncated.
When not to use it
- →When the user asks how to install or set up MC Bridge (use the setup instructions from the README).
Prerequisites
Limitations
- →Generated SQL uses ANSI-compatible syntax that works across Snowflake, BigQuery, Redshift, and Athena; minor adjustments may be needed for specific warehouse quirks.
- →The skill skips ephemeral models as they have no physical table.
- →The notebook name is truncated to under 50 characters.
How it compares
This skill automates the creation of dbt validation notebooks with schema inference and comparison queries, providing a direct import URL for Monte Carlo Bridge, which is more efficient than manually crafting validation queries and notebook
Compared to similar skills
generate-validation-notebook side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| generate-validation-notebook (this skill) | 0 | 3mo | Review | Intermediate |
| extract-test-set | 1 | 6mo | No flags | Intermediate |
| data-quality-frameworks | 0 | 3mo | No flags | Intermediate |
| cocoindex | 6 | 9mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
extract-test-set
tradingstrategy-ai
Extract raw price dataframe for a test case
data-quality-frameworks
Anhvu1107
ALWAYS use this when the request matches Data Quality Frameworks: Implement data quality validation with Great Expectations, dbt tests, and data contracts.
cocoindex
cocoindex-io
Comprehensive toolkit for developing with the CocoIndex library. Use when users need to create data transformation pipelines (flows), write custom functions, or operate flows via CLI or API. Covers building ETL workflows for AI data processing, including embedding documents into vector databases, building knowledge graphs, creating search indexes, or processing data streams with incremental updates.
similarity-search-patterns
wshobson
Implement efficient similarity search with vector databases. Use when building semantic search, implementing nearest neighbor queries, or optimizing retrieval performance.
sexp
atopile
How the Zig S-expression engine and typed KiCad models work, how they are exposed to Python (pyzig_sexp), and the invariants around parsing, formatting, and freeing.
api-test-generator
mikopbx
Генерация полных Python pytest тестов для REST API эндпоинтов с валидацией схемы. Использовать при создании тестов для новых эндпоинтов, добавлении покрытия для CRUD операций или валидации соответствия API с OpenAPI схемами.