Skip to main content

About documentation

Good documentation for your dbt models will help downstream consumers discover and understand the datasets you curate for them. dbt provides a way to generate documentation for your dbt project and render it as a website.

dbt Copilot available in beta
Use dbt Copilot, available in beta, to generate documentation in the dbt Cloud IDE only.

To use dbt Copilot, you must have an active dbt Cloud Enterprise account and either agree to use dbt Labs' OpenAI key or provide your own Open AI API key. Register here or reach out to the Account team to join the private beta.

Assumed knowledge

Overview

dbt provides a scalable way to generate documentation for your dbt project using descriptions and commands. The documentation for your project includes:

  • Information about your project: including model code, a DAG of your project, any tests you've added to a column, and more.
  • Information about your data warehouse: including column data types, and table sizes. This information is generated by running queries against the information schema.
  • Importantly, dbt also provides a way to add descriptions to models, columns, sources, and more, to further enhance your documentation.

The following sections describe how to add descriptions to your project, generate documentation, how to use docs blocks, and set a custom overview for your documentation.

Adding descriptions to your project

Before generating documentation, add descriptions to your project resources. Add the description: key to the same YAML files where you declare tests. For example:

models/<filename>.yml
version: 2

models:
- name: events
description: This table contains clickstream events from the marketing website

columns:
- name: event_id
description: This is a unique identifier for the event
tests:
- unique
- not_null

- name: user-id
quote: true
description: The user who performed the event
tests:
- not_null

FAQs

Are there any example dbt documentation sites?
Do I need to add a YAML entry for column for it to appear in the docs site?
How do I write long-form explanations in my descriptions?
How do I access documentation in dbt Explorer?
Can I document things other than models, like sources, seeds, and snapshots?

Generating documentation

Generate documentation for your project by following these steps:

  1. Run the dbt docs generate command to compile relevant information about your dbt project and warehouse into manifest.json and catalog.json files, respectively.
  2. Ensure you've created the models with dbt run or dbt build to view the documentation for all columns, not just those described in your project.
  3. Run the dbt docs serve command if you're developing locally to use these .json files to populate a local website.

dbt provides two complementary ways to view documentation, and your descriptions, after it's generated:

  • dbt Docs: A static documentation site with model lineage, metadata, and documentation that can be hosted on your web server (like S3 or Netlify). Available for dbt Core or dbt Cloud Developer plans.
  • dbt Explorer: Builds upon dbt Docs to provide a dynamic, real-time interface with enhanced metadata, customizable views, deeper project insights, and collaboration tools. Available on dbt Cloud Team or Enterprise plans.

See View documentation to get the most out of your dbt project's documentation.

Using docs blocks

Docs blocks provide a robust method for documenting models and other resources using Jinja and markdown. Docs block files can contain arbitrary markdown, but they must be uniquely named.

Syntax

To declare a docs block, use the Jinja docs tag. Their names may contain:

  • Can't start with a digit
  • Uppercase and lowercase letters (A-Z, a-z)
  • Digits (0-9)
  • Underscores (_)
events.md
{% docs table_events %}

This table contains clickstream events from the marketing website.

The events in this table are recorded by Snowplow and piped into the warehouse on an hourly basis. The following pages of the marketing site are tracked:
- /
- /about
- /team
- /contact-us

{% enddocs %}

In this example, a docs block named table_events is defined with some descriptive markdown contents. There is nothing significant about the name table_events — docs blocks can be named however you like, as long as the name only contains alphanumeric and underscore characters and doesn't start with a numeric character.

Placement

Usage

To use a docs block, reference it from your schema.yml file with the doc() function in place of a markdown string. Using the examples above, the table_events docs can be included in the schema.yml file as shown here:

schema.yml
version: 2

models:
- name: events
description: '{{ doc("table_events") }}'

columns:
- name: event_id
description: This is a unique identifier for the event
tests:
- unique
- not_null

In the resulting documentation, '{{ doc("table_events") }}' will be expanded to the markdown defined in the table_events docs block.

Setting a custom overview

Currently available for dbt Docs only.

The "overview" shown in the dbt Docs website can be overridden by supplying your own docs block called __overview__.

  • By default, dbt supplies an overview with helpful information about the docs site itself.
  • Depending on your needs, it may be a good idea to override this docs block with specific information about your company style guide, links to reports, or information about who to contact for help.
  • To override the default overview, create a docs block that looks like this:
models/overview.md
{% docs __overview__ %}
# Monthly Recurring Revenue (MRR) playbook.
This dbt project is a worked example to demonstrate how to model subscription
revenue. **Check out the full write-up [here](https://blog.getdbt.com/modeling-subscription-revenue/),
as well as the repo for this project [here](https://github.com/dbt-labs/mrr-playbook/).**
...

{% enddocs %}

Custom project-level overviews

Currently available for dbt Docs only.

You can set different overviews for each dbt project/package included in your documentation site by creating a docs block named __[project_name]__.

For example, in order to define custom overview pages that appear when a viewer navigates inside the dbt_utils or snowplow package:

models/overview.md
{% docs __dbt_utils__ %}
# Utility macros
Our dbt project heavily uses this suite of utility macros, especially:
- `surrogate_key`
- `test_equality`
- `pivot`
{% enddocs %}

{% docs __snowplow__ %}
# Snowplow sessionization
Our organization uses this package of transformations to roll Snowplow events
up to page views and sessions.
{% enddocs %}
0