Skip to main content
  1. posts/

how i use cursor and ai agents to write dbt tests and documentation

·2 mins· loading ·
 Author
Author
philip mathew hern
philliant
Table of Contents
cursor - This article is part of a series.
Part : This Article

quick answer
#

writing dbt tests and documentation is often the most neglected part of data engineering. i use cursor and custom ai agents to automate this process by reading my sql models, inferring the business logic, and generating the corresponding yaml files. this ensures high-quality data pipelines without the manual overhead.

who this is for
#

  • audience: data engineers, analytics engineers, and developers using dbt
  • prerequisites: basic knowledge of dbt, sql, and cursor
  • when to use this guide: when you want to scale your data engineering practices and reduce the time spent on writing boilerplate yaml

why this matters
#

documentation and testing are critical for data trust, but they are tedious to write manually. when these steps are skipped, data quality suffers and debugging becomes a nightmare. by automating this with ai, you get the benefits of rigorous testing and clear documentation while freeing up your time for higher-value architectural work.

step-by-step
#

1) define the starting point
#

most data engineers start with a raw sql model and a blank slate for their schema.yml file. the traditional approach requires manually typing out every column name, description, and test. this is prone to human error and inconsistency, plus almost always falls out of sync with current models with the first change.

2) apply the change
#

i use cursor to bridge this gap. by creating specific ai rules and skills, i can highlight a dbt model and ask the agent to generate the documentation. the agent reads the sql, understands the joins and transformations, and produces a complete yaml file with standard tests like not_null and unique. it can even infer complex relationships and suggest custom tests based on the data domain.

3) validate the result
#

once the ai generates the yaml, i review it for accuracy. i then run dbt test and dbt docs generate to ensure everything compiles correctly. the ai rarely makes syntax errors, so the validation step is mostly about confirming the business logic aligns with the documentation.

faq
#

what is the most important caveat?
#

you must still review the generated output. ai is excellent at scaffolding and inferring patterns, but it does not possess the full business context that you do.

what should i do first?
#

start by creating a simple cursor skill that defines your team’s standards for dbt documentation. feed it a few examples of your best schema.yml files so it learns your preferred style.

references
#

related reading#

cursor - This article is part of a series.
Part : This Article

Related