Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Documenting models in YAML
📖 Scenario: You are working on a data project using dbt. You have created some models (tables) and now want to add clear documentation for each model and its columns. This helps your team understand what each model and column means.
🎯 Goal: Learn how to write YAML files to document dbt models and their columns with descriptions.
📋 What You'll Learn
Create a YAML file with model documentation
Add model name and description
Add column names and descriptions
Use correct YAML syntax for dbt documentation
💡 Why This Matters
🌍 Real World
Documenting data models clearly helps teams understand data sources and improves collaboration.
💼 Career
Data analysts and engineers often write YAML documentation for dbt models to maintain data quality and clarity.
Progress0 / 4 steps
1
Create a YAML file with a model entry
Create a YAML file with a models key. Under it, add a model with the name orders and a description 'This model contains order data.'
dbt
Hint
Start with models: then add a list item with - name: orders and description:
2
Add columns section with one column
Under the orders model, add a columns key. Add one column with the name order_id and description 'Unique identifier for each order.'
dbt
Hint
Indent columns: under the model, then add a list item with - name: order_id and description:
3
Add a second column with description
Add another column under columns with the name order_date and description 'Date when the order was placed.'
dbt
Hint
Add another list item under columns: with the new column name and description.
4
Print the full YAML content
Print the full YAML content stored in a variable called yaml_doc. Assign the entire YAML text to yaml_doc as a multi-line string, then print it.
dbt
Hint
Use triple quotes to assign the YAML text to yaml_doc and then print it.
Practice
(1/5)
1. What is the main purpose of documenting models in YAML in a dbt project?
easy
A. To write SQL queries inside YAML files
B. To execute dbt models automatically
C. To add clear descriptions for models and columns to improve understanding
D. To store raw data files
Solution
Step 1: Understand the role of YAML documentation
YAML files in dbt are used to add metadata like descriptions, not to run code or store data.
Step 2: Identify the benefit of documentation
Adding descriptions for models and columns helps team members understand the data and maintain the project easily.
Final Answer:
To add clear descriptions for models and columns to improve understanding -> Option C
Quick Check:
Documentation purpose = Add descriptions [OK]
Hint: Documentation in YAML means adding descriptions, not code [OK]
Common Mistakes:
Thinking YAML runs SQL code
Confusing YAML with data storage
Ignoring the importance of descriptions
2. Which of the following is the correct way to start documenting a model named orders in a YAML file?
easy
A. models:
orders
description: 'Contains order details'
B. model:
name: orders
description: 'Contains order details'
C. models:
- orders:
description: 'Contains order details'
D. models:
- name: orders
description: 'Contains order details'
Solution
Step 1: Recall YAML syntax for dbt model documentation
dbt expects a list under models: with each model as a dictionary containing name and description.
Step 2: Match the correct structure
models:
- name: orders
description: 'Contains order details' correctly uses a list with a dictionary having name and description. Other options misuse keys or structure.
Final Answer:
models:
- name: orders
description: 'Contains order details' -> Option D
Quick Check:
Model list with name and description = models:
- name: orders
description: 'Contains order details' [OK]
Hint: Use dash (-) for list items under models in YAML [OK]
Common Mistakes:
Using singular 'model' instead of 'models'
Not using dash for list items
Incorrect indentation or key names
3. Given this YAML snippet documenting a model and its columns:
A. Missing dash (-) before column name and description
B. Incorrect model name key
C. Description should be under models, not columns
D. YAML does not support nested lists
Solution
Step 1: Check YAML list syntax for columns
Each column should be a list item with a dash (-) before its dictionary of keys.
Step 2: Identify missing dash in columns
The name and description keys under columns lack the dash, so YAML treats them as keys of columns instead of list items.
Final Answer:
Missing dash (-) before column name and description -> Option A
Quick Check:
List items need dash (-) in YAML [OK]
Hint: Use dash (-) before each column in columns list [OK]
Common Mistakes:
Forgetting dash for list items
Misplacing description keys
Confusing YAML lists and dictionaries
5. You want to document two models, users and transactions, each with columns and descriptions. Which YAML structure correctly documents both models with their columns?