Skip to main content
AI Guardrails for dbt

AI Guardrails for dbt

On December 10 I’m presenting “AI Guardrails for dbt” at the NYC dbt Meetup. If you can’t make it, here’s the short version, with links to the real docs for each tool and the slides to download at the bottom.

The Job Changed

Writing code used to be the bottleneck. More output meant hiring more people or learning faster. A one-person team can now ship what used to take twenty, and run into the same scale problems: models nobody has read, tests that pass for the wrong reasons, metrics that drift between dashboards.

A single highlighted person icon among a grid of greyed-out ones.

Agents write the code now. Judgment is what’s left, and it matters more than it used to.

Big Idea 1: Make It Deterministic

A prompt like “check that every model has tests” is probabilistic. Likely, never guaranteed. A script that does the same check is deterministic: same input, same result, every time.

Side by side: dice icons labeled probabilistic (prompts, context, skills) next to a terminal icon labeled deterministic (scripts, hooks, pre-commit, CI/CD).

Don’t ask the AI to do the task. Ask it to write the script that does it, then run the script every time.

Big Idea 2: Validation Is the New Bottleneck

There’s a spectrum here, in order of how much you can trust it:

  1. A human reviews every line
  2. The agent checks its own work
  3. A script validates the output
  4. A hook blocks actions that produce bad code before they even run

Most teams are stuck at 1 or 2. The guardrails worth building live at 3 and 4.

The Toolkit

dbt already gave data teams guardrails most codebases don’t have: version control, tests, CI/CD, a semantic layer. AI needs the same kind of scaffolding.

Two parallel columns: dbt's guardrails (version control, modularity, tests, documentation, lineage, CI/CD, semantic layer, macros) plus AI's equivalents (AGENTS.md, prompts, context, skills, MCP, hooks, sub-agents, evals).

Here’s where the pieces actually live in a repo:

A directory tree for a dbt project, annotating .agents/skills as Skills, .github/workflows as CI/CD, CODEOWNERS as human review, .your-agent as Hooks, .mcp.json as MCP servers, .pre-commit-config.yaml as pre-commit, .sqlfluff as SQL lint rules, AGENTS.md as conventions, and dbt-bouncer.yml as dbt-bouncer.

AGENTS.md

An open convention for briefing a coding agent on a project, the same way a README briefs a person. A README is written for a human to skim; AGENTS.md is a predictable, structured spot for what an agent needs: what the project does, the rules that never bend, and where to find everything else. It isn’t tied to one vendor. Most AI coding tools now look for the nearest AGENTS.md in the directory tree before touching anything, which is what makes it worth writing once instead of once per tool.

Read the spec →

Skills

A skill is a folder: a SKILL.md with instructions, plus any scripts it needs, that an agent loads only when a task matches its one-line description. The description stays in context cheaply at all times. The full instructions, and any scripts that run as real code instead of model guesswork, only load once a task calls for them. That’s what lets a project carry dozens of skills without every one of them competing for space in the context window.

Claude Code’s Agent Skills docs →

The dbt MCP Server

MCP (the Model Context Protocol) is an open protocol for connecting an agent to real external tools instead of letting it answer from memory. The dbt MCP server is dbt Labs’ implementation of it: it gives an agent tools to run dbt commands, read lineage, pull model docs, and query the Semantic Layer directly against your actual project, so “what does this model do” gets answered by reading it, not guessing from the name.

About the dbt MCP server →

The Semantic Layer

dbt’s Semantic Layer lets you define a metric’s aggregation and filters once, as code, instead of five dashboards each computing “revenue” a slightly different way. MetricFlow compiles that one definition to SQL on the fly for whichever tool or agent is asking, so every consumer gets the same answer.

dbt Semantic Layer docs →

Hooks

In Claude Code, a hook is a script you register that the harness runs automatically at a lifecycle event: before a tool call, after an edit, when the agent stops, whether or not the model would have chosen to run it. Exit code 2 blocks the action and hands the agent the reason, so it can fix the real problem instead of retrying blind.

Claude Code hooks docs →

pre-commit

A framework for running checks (linting, formatting, your own scripts) on every commit, configured once in .pre-commit-config.yaml. It doesn’t know or care whether the commit came from a person or an agent, and the same config runs again in CI, so --no-verify is the only way around it locally.

pre-commit.com →

dbt-bouncer

An open-source tool that reads your project’s manifest.json right after dbt parse and checks it against rules you set in dbt-bouncer.yml: naming conventions, folder structure, required tests. Break a rule and the check fails, which fails the PR.

dbt-bouncer docs →

Sub-agents

A sub-agent is a second agent definition (its own markdown file, usually scoped to a narrower set of tools) that starts with fresh context and one job, like reviewing a diff. It has no memory of how the code got written, so it isn’t anchored to the first agent’s reasoning about its own output.

Claude Code’s sub-agents docs →


None of this requires a big-bang rewrite. Write an AGENTS.md. Connect the MCP server. Ask the AI to write one deterministic script instead of doing the task by hand. Add pre-commit. The rest follows.

Slides

Download the full deck (PDF)

If you’re in New York on the 10th, come say hi.