Skip to content

Skill to add unit tests to a dbt project#13

Merged
b-per merged 22 commits intomainfrom
dbeatty/unit-tests
Jan 29, 2026
Merged

Skill to add unit tests to a dbt project#13
b-per merged 22 commits intomainfrom
dbeatty/unit-tests

Conversation

@dbeatty10
Copy link
Copy Markdown
Contributor

resolves #

Description

Checklist

Copy link
Copy Markdown
Contributor

@jasnonaz jasnonaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bunch of comments, mostly around splitting out some logic in here that probably doesn't need to live in the main skill.

I feel like this is a lot of what, some how and very little why. To the extent we can bake in more opinioned / high signal heuristics for the models we should attempt to.

Comment thread dbt-unit-tests/skills/add-unit-test/SKILL.md Outdated
Comment thread dbt-unit-tests/skills/add-unit-test/SKILL.md Outdated
dbt unit test uses a trio of the model, given inputs, and expected outputs (Model-Inputs-Outputs):

1. `model` - when building this model
2. `given` inputs - given a set of source, seeds, and models as preconditions
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. `given` inputs - given a set of source, seeds, and models as preconditions
2. `given` inputs - given a set of source, seeds, macros and models as preconditions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since macros go under overrides rather than under given, I'm not going to commit this as-is.

But good point that macros fall under the inputs / pre-conditions umbrella (along with project variables and environment variables).

So we'll either want to add that info here or just leave it to the later sections that cover those scenarios

Comment thread dbt-unit-tests/skills/add-unit-test/SKILL.md Outdated
Comment thread dbt-unit-tests/skills/add-unit-test/SKILL.md Outdated
## `sql`

Using this format:
- Provides more flexibility for the unit testing column that have a data type not supported by the `dict` or `csv` formats
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THIS is great - this is the stuff we keep


# Special cases

## Unit testing incremental models
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incremental and versioned examples should live in their own file with callouts that these are special cases and the model should look into it. For the most part - keep the prose,, move the code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e395b1d

Comment thread dbt-unit-tests/skills/add-unit-test/SKILL.md
1. There was an error in the way the unit test was constructed (false positive)
2. There is an bug is the model (true positive)

It takes expert judgement to determine one from the other.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have some guidance on how to determine one from the other?


```

### Fixture files
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed given the above section talking about files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially addressed in 5719ff4.

Can revisit to consolidate any duplicated content.

@@ -0,0 +1,3 @@
# Caveats for BigQuery
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really think we need this type of info! Thanks for adding.

My comments:

  • is caveat the correct word here? if we add recommendations and best practices for other parts in dbt for BQ, those might not be caveats. I like instructions_bigquery.md or something like that
  • we could add all of those under a specific folder for adapter/warehouse specific instructions
  • we should call out the name of the file in any skill that would need to get this information, otherwise the LLM will not look at it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should call out the name of the file in any skill that would need to get this information, otherwise the LLM will not look at it

✅ Done!

is caveat the correct word here? if we add recommendations and best practices for other parts in dbt for BQ, those might not be caveats. I like instructions_bigquery.md or something like that

One definition of caveat is "specific stipulations, conditions, or limitations", so it is a good descriptor in this case. We can call it whatever we want though, and I don't feel strongly either way.

we could add all of those under a specific folder for adapter/warehouse specific instructions

Are you thinking something like this within a subfolder with simply the name of the adapter/warehouse?

my-skill/
├── SKILL.md
└── adapter/
    ├── bigquery.md (adapter/warehouse specific instructions - loaded when needed)
    ├── databricks.md (adapter/warehouse specific instructions - loaded when needed)
    ├── redshift.md (adapter/warehouse specific instructions - loaded when needed)
    └── snowflake.md (adapter/warehouse specific instructions - loaded when needed)

Or flat like this?

my-skill/
├── SKILL.md
├── bigquery.md (adapter/warehouse specific instructions - loaded when needed)
├── databricks.md (adapter/warehouse specific instructions - loaded when needed)
├── redshift.md (adapter/warehouse specific instructions - loaded when needed)
└── snowflake.md (adapter/warehouse specific instructions - loaded when needed)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually thinking of a third option (close to the 1st one)

my-skill1/
└── SKILL.md
my-skill2/
└── SKILL.md
adapter/
    ├── bigquery.md (adapter/warehouse specific instructions - loaded when needed)
    ├── databricks.md (adapter/warehouse specific instructions - loaded when needed)
    ├── redshift.md (adapter/warehouse specific instructions - loaded when needed)
    └── snowflake.md (adapter/warehouse specific instructions - loaded when needed)

The adapter specific things we'd have to say will be short enough that we can have 1 file to cover all the skills.

Copy link
Copy Markdown
Contributor Author

@dbeatty10 dbeatty10 Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 2542c0f, fdaf6ab, and dd24b72.

We can move it around / rename it further as-needed.

Copy link
Copy Markdown
Contributor

@b-per b-per left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY Doug! Added some comments


## What are unit tests in dbt

In software programming, unit tests validate small portions of your functional code, and they work much the same way in dbt. dbt uwnit tests allow you to validate your SQL modeling logic on a small set of static inputs _before_ you materialize your full model in production. dbt unit tests enable test-driven development, benefiting developer efficiency and code reliability.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In software programming, unit tests validate small portions of your functional code, and they work much the same way in dbt. dbt uwnit tests allow you to validate your SQL modeling logic on a small set of static inputs _before_ you materialize your full model in production. dbt unit tests enable test-driven development, benefiting developer efficiency and code reliability.
In software programming, unit tests validate small portions of your functional code, and they work much the same way in dbt. dbt unit tests allow you to validate your SQL modeling logic on a small set of static inputs _before_ you materialize your full model in production. dbt unit tests enable test-driven development, benefiting developer efficiency and code reliability.

@@ -0,0 +1,42 @@
See below for all the required and optional keys in the YAML definition of unit tests.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes to this type of info!!!

This is the information dense type of content that is maybe too dense for humans to reason through, but it is exactly what LLMs need!


This example creates a new `dim_customers` model with a field `is_valid_email_address` that calculates whether or not the customer’s email is valid:

<file name='dim_customers.sql'>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't used this `<file ...> syntax in the other skills. Open question, should we do it everywhere or should we not use it? I think we should be consistent though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use the following syntax within bcf4292:

`models/schema.yml`

```yaml
# stuff
```

- Verifying that a bug fix solves a bug report for an existing dbt model.

More examples:
- When your SQL contains complex logic:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add complex joins logic?


Self explanatory -- the title says it all!

### 2. Mock the inputs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we recommend using dbt show to explore the existing inputs/outputs and sanitize them to make sure they don't contain sensitive data?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fantastic idea!

Might even be a good stand-alone and reusable skill.

Comment thread dbt-unit-tests/skills/add-unit-test/SKILL.md
@dbeatty10
Copy link
Copy Markdown
Contributor Author

From Benoit in internal slack:

I just did a quick demo/test of running the evals on top of your skill (video)

Doing it I saw that we might need to tweak the skill name and/or description

Would you be OK trying to add a scenario where you provide an existing dbt project as context and ask to add some unit tests (like you did by hand) ; but this time having one case without the skill and one case with the skill?

- Add complex joins to list of scenarios that warrant unit tests
- Add tip to use dbt show for exploring input data with sanitization reminder
@b-per
Copy link
Copy Markdown
Contributor

b-per commented Jan 29, 2026

Merging this for now as a v1 🚀

@b-per b-per marked this pull request as ready for review January 29, 2026 16:25
@b-per b-per requested a review from a team as a code owner January 29, 2026 16:25
@b-per b-per merged commit 531e6cc into main Jan 29, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants