Skip to content
All projects

Case study · Data Engineering · AI Engineering · Architecture

Claude Code Data Template: Guardrails for AI on Data Projects

A dbt + DuckDB starter where Claude Code follows data rules, and hooks block DROP, production targets and secrets before they run.

The problem

AI coding agents write SQL fast. They can also run DROP TABLE, point dbt at production, or make a failing test pass by turning a LEFT JOIN into an INNER JOIN. Rules in a prompt help, but they are only advice.

Constraints

  • Guardrails live in the repository, so every session and every teammate gets them
  • Hooks must be plain Python with no dependencies, and tested exactly as Claude Code calls them
  • Normal work must stay fast: dbt runs, tests and dev queries need no approval

Architecture and decisions

Click a box to see why it was chosen.

Claude Code data guardrailsRules
CLAUDE.mdlayers, grain, done
Permissionsdbt allowed, .env hidden
Before a tool runs
guard_bashDROP, prod, force push
guard_filessecrets, .env
After an edit
check_modeltests, no SELECT *
Helpers
Subagentsreviewer, investigator
Skillsnew-model, reconcile
dbt + DuckDBdemo shop, 12 tests

Why · CLAUDE.md

Project rules: layers, naming, grain in every description, tests on every key, and what "done" means: row counts compared before and after.

Results

hook tests, each run the way Claude Code runs it
34
hook tests, each run the way Claude Code runs it
risky commands blocked before they run, plus secrets in files
6
risky commands blocked before they run, plus secrets in files
dbt data tests, including a reconciliation test
12
dbt data tests, including a reconciliation test
subagents and skills for review, incidents, new models and reconciling
2 + 2
subagents and skills for review, incidents, new models and reconciling

What I would do next

  1. 01A Stop hook that runs dbt tests before Claude ends a turn
  2. 02Warehouse versions of the guards for Snowflake and BigQuery targets