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.
Related documentation
- Declaring properties
dbt docscommanddocJinja function- If you're new to dbt, we recommend that you check out our quickstart guide to build your first dbt project, complete with documentation.
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 data tests. For example:
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
data_tests:
- unique
- not_null
- name: user-id
quote: true
description: The user who performed the event
data_tests:
- not_null
FAQs
Generating documentation
dbt provides both self-hosted and cloud-hosted solutions to view documentation for your project. Which one you use depends on your dbt version and where you run dbt.
(Applies to dbt v2.0 and later)| Option | What it is | Where you use it | How to generate it |
|---|---|---|---|
| dbt Docs v2 | A redesigned, open-source documentation site with Semantic Layer metadata and column-level lineage that you can host anywhere | Locally with dbt v2. Not available in dbt platform | Run dbt docs generate locally. Refer to generate docs locally for steps |
| dbt Catalog | A dynamic, real-time interface with enhanced metadata, customizable views, deeper project insights, and collaboration tools. | dbt platform Starter, Enterprise, or Enterprise+ plans | Populated automatically when your jobs run with dbt v2. No extra step required! |
Anyone with a developer or read-only seat can explore your project(s) in Catalog. Add as many read-only seats as you need to share docs with stakeholders, no separate docs site required.
Generate docs locally
(Applies to dbt v2.0 and later)Using dbt v2, dbt Docs v2 enhances the original v1 static site with a modern, performant catalog. dbt docs generate compiles your project, produces the v2 Parquet artifacts, and writes a static site that the browser queries directly with DuckDB-WASM (WebAssembly), so you don't need a server to view it.
To generate and serve documentation locally:
- Run
dbt docs generateto compile your project, write the index, and export the documentation site in a single command. - Run
dbt docs serveto preview the site locally.
dbt Docs v2 only works self-hosted installations of dbt v2. If you're on the dbt platform, use Catalog which is populated automatically when your jobs run with v2. Adding a dbt docs generate step to a job won't produce a static site in dbt platform.
Refer to dbt docs commands for full usage details, and View documentation to get the most out of your 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. The name of a docs block can't start with a digit and may contain:
- Uppercase and lowercase letters (A-Z, a-z)
- Digits (0-9)
- Underscores (_)
{% 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
(Applies to dbt v1.12 and later)Place docs blocks in .md files. You can also use Jinja-style extensions (.md.j2, .md.jinja, .md.jinja2), however these require setting allow_jinja_file_extensions: true in your dbt_project.yml. This enables Jinja-aware syntax highlighting in IDEs that associate these suffixes with Jinja templating.
By default, dbt searches in all resource paths for docs blocks (for example, the combined list of model-paths, seed-paths, analysis-paths, test-paths, macro-paths, and snapshot-paths). You can adjust this behavior using the docs-paths config.
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:
models:
- name: events
description: '{{ doc("table_events") }}'
columns:
- name: event_id
description: This is a unique identifier for the event
data_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
This feature is available only in dbt Docs, the generated documentation site for your dbt project.
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:
{% 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
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:
{% 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 %}
Was this page helpful?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.