0
0
dbtdata~15 mins

Doc blocks for reusable descriptions in dbt - Mini Project: Build & Apply

Choose your learning style9 modes available
Doc blocks for reusable descriptions
📖 Scenario: You are working on a data analytics project using dbt. You want to keep your documentation clear and avoid repeating the same descriptions for columns in multiple models. To do this, you will use doc blocks to create reusable descriptions.
🎯 Goal: Create a doc block with a reusable description and apply it to a column in a dbt model's schema file.
📋 What You'll Learn
Create a doc block named customer_id_description with a clear description text.
Create a schema file with a model named orders.
Use the doc block customer_id_description as the description for the customer_id column in the orders model.
💡 Why This Matters
🌍 Real World
In real data projects, many columns share the same meaning across tables. Using doc blocks avoids repeating descriptions and reduces errors.
💼 Career
Data analysts and engineers use dbt documentation features like doc blocks to maintain clear, consistent, and professional data documentation.
Progress0 / 4 steps
1
Create a doc block with a reusable description
Create a doc block named customer_id_description with the description text: 'Unique identifier for each customer' inside a docs block in your schema.yml file.
dbt
Need a hint?

Use the docs key at the top level, then add - name: customer_id_description followed by description: "Unique identifier for each customer" with proper indentation (2 spaces for the list item, 4 spaces for description).

2
Create a schema file with a model named orders
Add a model named orders under the models key in the same schema.yml file. Define a column named customer_id inside the columns list for the orders model.
dbt
Need a hint?

Under models, add a list item with name: orders and a columns list containing name: customer_id.

3
Use the doc block as the description for the customer_id column
In the orders model's customer_id column, add a description key that uses the doc block customer_id_description with the syntax description: '{{ doc("customer_id_description") }}'.
dbt
Need a hint?

Use the description key with the value '{{ doc("customer_id_description") }}' exactly as shown.

4
Print the final schema.yml content
Print the entire content of the schema.yml file to verify the doc block and model column description are correctly set.
dbt
Need a hint?

Assign the full YAML content as a string to schema_yml_content and print it.