Skip to content

Documentation

Course map · Previous: Tests · Next: Deployment

A doc block in the yml becomes the docs site

Descriptions in *_schema.yml become the docs site. Longer text lives in {% docs %} blocks in *_doc.md files, used with '{{ doc("name") }}'. See order_status in stg_jaffle_shop_doc.md.

Open Run (from oms_dbt_proj)
models/**/*_doc.md dbt docs generate --profiles-dir . then dbt docs serve --profiles-dir .

The same descriptions show up in the ERD that qdbd builds from dbt docs generate output.

Learn

Docs kept in a separate tool fall behind the code. dbt keeps them next to it:

  • Every model, source and column can have a description: in its YAML file.
  • For longer text with tables or lists, write a doc block in a .md file and point to it with doc():
{% docs order_status %}
One of the following values: placed, shipped, completed, return pending, returned.
{% enddocs %}
      - name: status
        description: '{{ doc("order_status") }}'

dbt docs generate builds a website from all of it: descriptions, the tests on each column, each model's SQL, and the lineage graph. dbt docs serve opens it.

Quiz

Where do column descriptions for dim_customers live?

  • In comments inside dim_customers.sql
  • In marketing_schema.yml, beside the model
  • In the docs site, edited by hand
Answer

In the YAML beside the model. Docs live next to the code, so they change in the same pull request. dbt docs generate reads them into the site.

You wrote {% docs order_status %} in a _doc.md file. How does a column use it?

  • description: order_status
  • {{ ref('order_status') }} in the model SQL
  • description: '{{ doc("order_status") }}'
Answer

doc() in a description. See the status column in stg_jaffle_shop_schema.yml. The quotes matter: YAML needs them around {{ }}.

Which command writes the docs site, including the lineage graph?

  • dbt docs generate
  • dbt docs serve
  • dbt compile
Answer

dbt docs generate. It writes manifest.json, catalog.json and the site into target/. dbt docs serve only serves what generate wrote.

Try it

Write a lifetime_value doc block and use it for dim_customers.lifetime_value.

Hint

You need two edits: a new models/marts/marketing/marketing_doc.md with the {% docs %} block, and a lifetime_value entry in marketing_schema.yml that points at it.

Answer

Create models/marts/marketing/marketing_doc.md:

{% docs lifetime_value %}
Total of successful payments, in dollars, across all of a customer's orders.
NULL when the customer has no orders.
{% enddocs %}

Add this to the end of the columns: list in models/marts/marketing/marketing_schema.yml:

  - name: lifetime_value
    description: '{{ doc("lifetime_value") }}'
dbt docs generate --profiles-dir .
dbt docs serve --profiles-dir .

Open dim_customers in the docs site (http://localhost:8080). The lifetime_value column shows your text. Press Ctrl+C to stop the server.