← All posts

Data Engineering · 7 min read

Agents for data modelling: drafting dbt models, tests and docs with review gates

Agents can now draft a staging model, its tests and its YAML docs in minutes. The hard part is knowing the result is right. Here's how the current dbt tooling works, what teams that use it have learned, and the review gates that keep agent-written models out of trouble.

Subhash Nunna ·

A lot of data modelling work is careful but repetitive. A new source lands, and someone writes the source YAML, a staging model that renames and casts columns, not_null and unique tests on the keys, and descriptions for forty columns. Then a mart on top, then a metric.

Agents are now good at drafting all of that. The tooling has matured over the last year: dbt Labs ships an agent inside its IDE, an MCP server gives any agent access to a dbt project, and several teams have published honest accounts of what happened when they let agents write models. The common finding is simple. Generating the code is the easy part. Knowing the data is right is the product.

This post covers how agents plug into a dbt project, what they’re good and bad at, and the review gates that make agent-written models safe to merge. (For the wider view of agents in data work, see our post on data engineering agents.)

How agents plug into a dbt project

There are two main routes today.

An agent built into the dbt platform. dbt Labs’ docs describe dbt Wizard in the Studio IDE (a preview feature, last updated October 2026) as able to generate models, tests, docs and Semantic Layer definitions, and to “generate and validate YAML for tests, documentation, semantic models, and metrics.” It “shows file diffs before changes are persisted” and has three modes: Explore only (“can’t edit files or run builds”), Ask for approval (the default — “You approve each file change before it is persisted”) and Edit files automatically. It also asks before running commands like dbt compile or dbt build.

Your own agent plus the dbt MCP server. If you use a general coding agent, the open-source dbt MCP server exposes the project as tools. Its documentation (updated November 2026) groups them into categories, including:

Category Example tools What an agent uses them for
Discovery get_all_sources, get_lineage, get_node_details, get_model_health Understanding what already exists before writing anything
dbt CLI (local) parse, compile, build, test, show Checking that a draft compiles, runs and passes tests
Codegen (local) generate_source, generate_staging_model, generate_model_yaml Deterministic scaffolding for sources, staging models and YAML
Semantic Layer list_metrics, get_dimensions, query_metrics Reusing defined metrics instead of reinventing them
SQL execute_sql, text_to_sql Profiling data and ad hoc queries

Two details from that page matter for guardrails. The CLI tools carry a warning that they “could modify your data models, sources, and warehouse objects.” And execute_sql “doesn’t block write statements.” Whatever an agent can do here depends on the credentials you give it.

A practical tip: let the Codegen tools do the scaffolding. A generated staging model and YAML skeleton are deterministic, so the model only has to fill in what needs judgement — names, descriptions, tests and business logic.

What agents do well

Teams that have written about this agree on where agents save real time:

  • Boilerplate. Source YAML, staging models, column descriptions and the obvious tests. dbt Labs’ own overview says AI “can generate basic tests,” leaving engineers to focus on edge cases and business logic.
  • Mechanical SQL. In a hands-on session written up by Jason Ganz in April 2026, an agent “one-shotted” a sessionisation model “with the five CTEs needed to do the lead, the lag, add the session ID, and everything.”
  • Profiling. In the same session, a data profiling step went from about three minutes to ten seconds. The engineer estimated a 2–3x overall speedup, and Ganz notes that self-reported productivity gains “are often unreliable and need to be verified with other mechanisms.”

Where they go wrong

The failures are rarely syntax errors. They are models that compile, pass tests and are still wrong.

Same name, different meaning. In Ganz’s write-up, two user ID columns shared a name: one raw, one hashed with tenant context further down the pipeline. The agent joined on them. In his words: “The SQL the agent wrote was clean, the joins were wrong, and the tests all passed.” It surfaced only when a distribution check showed some IDs appearing far too often.

Ambiguous business terms. Careem’s data team, presenting at dbt Summit 2026, gave the example of “revenue,” which could mean GTV, GMV or order count. Their agent is designed to ask rather than guess.

Plausible but not production-ready. Robin Moffatt built an eval in which Claude models built a dbt project, across rich and minimal prompts and different skill setups. Deterministic checks and an LLM judge (a 9-criterion rubric, each scored 0–3) found failures such as a dimension not built from its snapshot, so history was lost, and one run that truncated input dimension data by about 60%. His conclusion: “None of the tests produced a dbt project that was sufficiently good to take through to production,” though the models did “a pretty good job, given a sufficiently rich prompt.”

Side effects. In Ganz’s session the agent ran LLM-powered model functions without asking, burning tokens. Expensive or stateful actions need explicit permission.

The review gates that matter

Careem’s account is the most complete published example of an agent pipeline for dbt. They report supporting 5,000+ models, and say “roughly 90%” of new models now come from the framework. Those figures are self-reported in a conference talk summary, but the structure is worth copying. Their engineers put it plainly: “The generator is easy. The validation layer is the product.”

Combining their design with the other sources gives five gates:

  1. Lock the spec before writing code. Careem’s agent must confirm grain, metric definition and filters first. This catches the “revenue” problem up front.
  2. Sandbox everything. Careem runs agent work with separate IAM roles, storage paths and compute, so changes can’t touch production. For your own agent, that means a dev target and credentials that can’t write to production schemas — remember execute_sql won’t stop a DROP.
  3. Make the agent reach a clean run itself. Careem’s loop compiles, tests and materialises each change and fixes its own errors. In their demo, the first run failed on a type mismatch and the second because a column lived in another table; both were fixed before a human saw anything. Humans review only clean runs.
  4. Check the data, not just the code. Add checks that dbt tests often miss: row counts versus the source, distinct counts on keys, distributions of IDs and amounts, and a comparison with the existing model if you’re refactoring. Ganz’s bug was caught this way, not by tests.
  5. Merge through a normal pull request. Diffs, CI, and a reviewer who owns the domain. dbt Labs’ own guidance is that teams “should always validate AI output carefully” and that “testing before deployment is essential.”

A starter prompt

If you’re wiring up your own agent with the dbt MCP server, a task prompt like this captures most of the gates:

Task: add a staging model and tests for source `billing.invoices`.

Before writing code:
- Use discovery tools to list existing models that already use this source.
- State the grain (one row per what?) and any ambiguous columns. Stop and ask me
  if a column name matches one elsewhere in the project but may mean something else.

Then:
- Use generate_source and generate_staging_model to scaffold. Only rename, cast
  and document; no joins or business logic in staging.
- Add unique + not_null tests on the primary key and accepted_values where obvious.
- Run parse, build and test against the dev target only. Fix errors until clean.
- Report: row count vs source, distinct key count, and any assumptions you made.

Never run commands against prod. Never run execute_sql with DDL or DML.

Trade-offs

  • Speed versus review load. Agents can produce models faster than people can review them. If review becomes a rubber stamp, you’ve moved the risk, not removed it.
  • Context quality caps output quality. Agents lean on descriptions, lineage and a glossary. Careem built a context layer with metadata, lineage and business terms; projects without one will see more guessing.
  • Evaluation is still mostly do-it-yourself. Published numbers are vendor-reported or from small personal evals. Moffatt’s advice is useful: run deterministic validation first, and only spend tokens on an LLM judge if it passes.
  • Autonomy settings drift. “Edit files automatically” is convenient. Keep it for sandboxes.

Where to start

  1. Start with staging and docs. Use an agent on new sources and undocumented models, where the logic is thin and mistakes are easy to spot.
  2. Give it read-heavy access. Discovery and Codegen tools, CLI commands on a dev target, no production credentials.
  3. Write three data checks you’ll run on every agent-written model: row count, key uniqueness and one distribution check.
  4. Require a clean run before review, and review through pull requests like any other change.
  5. Keep a small eval set — five past modelling tasks with known-good answers — and re-run it when you change models, prompts or skills.

dbtdata modellingAI agentsdata engineeringevaluation