Model-Level Meta Fields
As your dbt project scales from 10 models to 1,000 models, managing the data becomes less about writing SQL, and more about Data Governance.
If a business analyst is looking at the fct_customer_transactions table, they might have questions:
- Who owns this table?
- Does it contain PII (Personally Identifiable Information)?
- Is this table updated daily or hourly?
You can answer all these questions directly in your dbt code using Meta Fields.
Topics Covered
- What are Meta Fields?
- Configuring Meta Fields in
schema.yml - Viewing Meta Fields in dbt Docs
- Advanced Use Cases (Macros)
1. What are Meta Fields?
meta is a property in dbt that allows you to attach custom, arbitrary key-value pairs (metadata) to your models, sources, seeds, or even individual columns.
Unlike description (which is just a text string), meta accepts structured YAML dictionaries. This means external tools (like Data Catalogs or custom Python scripts) can programmatically read these tags from the manifest.json file.
2. Configuring Meta Fields
Let's assume our data engineering team in Hyderabad wants to enforce strict ownership and PII tracking on all core models.
You define meta properties in your schema.yml file.
version: 2
models:
- name: fct_customer_transactions
description: "Core fact table for all financial transactions."
# Model-Level Meta
meta:
owner: "Arjun Kumar"
department: "Finance"
contains_pii: true
sla_tier: "Tier 1"
refresh_frequency: "Hourly"
columns:
- name: transaction_id
description: "Unique ID of the transaction."
tests:
- unique
- not_null
- name: customer_email
description: "Email address of the customer."
# Column-Level Meta
meta:
is_pii: true
masking_policy: "email_mask"
Because meta accepts arbitrary key-value pairs, you can invent whatever tags your specific company needs! sla_tier is not a built-in dbt concept; we just made it up.
3. Viewing Meta Fields in dbt Docs
The most immediate benefit of adding meta fields is that they automatically appear in your auto-generated dbt Docs site.
When you run dbt docs generate and dbt docs serve, any user who clicks on fct_customer_transactions will see a "Details" panel on the right side of the screen.
Underneath the description, they will see a neat table listing:
- owner: Arjun Kumar
- department: Finance
- contains_pii: True
This turns your dbt Docs from a simple data dictionary into a full-fledged Data Catalog.
4. Advanced Use Cases: Accessing Meta in Macros
The real power of meta properties is that you can read them dynamically inside your Jinja macros using the graph object.
For example, imagine you want to write a macro that automatically applies a Snowflake Data Masking policy to any column where meta.is_pii == true.
(Note: Advanced Jinja is covered later in the course, but here is a conceptual example).
{% macro apply_pii_masking() %}
-- Loop through all models in the project
{% for node in graph.nodes.values() %}
-- Loop through all columns in the model
{% for column_name, column in node.columns.items() %}
-- Check the column's meta properties!
{% if column.meta.get('is_pii') == true %}
-- Run the Snowflake DDL to apply the mask
{% set sql %}
ALTER TABLE {{ node.database }}.{{ node.schema }}.{{ node.name }}
MODIFY COLUMN {{ column_name }}
SET MASKING POLICY {{ column.meta.get('masking_policy') }};
{% endset %}
{% do run_query(sql) %}
{% endif %}
{% endfor %}
{% endfor %}
{% endmacro %}
By standardizing your meta tags, you can build powerful, automated Data Governance pipelines.
Summary
metafields allow you to attach arbitrary key-value pairs to models and columns.- Define them in your
schema.ymlfiles. - Common use cases include tracking Data Owners, PII flags, and SLA tiers.
- Meta fields automatically render in the dbt Docs website.
- You can access
metafields programmatically via themanifest.jsonor dynamically inside Jinja macros.