Back to tutorials

dbt Exposures: Usage & Examples

dbt has revolutionized the way data teams view and handle transformations. Within this ecosystem, dbt exposures stand out as a powerful feature that bridges the gap between raw data models and their downstream applications. In essence, exposures allow you to define and describe how your dbt project is utilized downstream, be it in a dashboard, application, or data science pipeline.

Why Use dbt Exposures?

Imagine making a change to a core data model and not knowing how it might affect the monthly sales dashboard the CEO looks at. This is where exposures come in. They provide:

  • Downstream Impact Analysis: Understand potential impacts of changes made to data models.
  • Time-saving: No need to reverse engineer data sources or analytics assets.
  • Enhanced Documentation: Every exposure gets its dedicated page in the autogenerated documentation site, providing clarity to data consumers.

Defining Exposures: A Step-by-Step Guide

Understanding Downstream Usage

Before defining an exposure, identify what downstream tools or reports rely on your dbt models. For instance, a sales dashboard in Looker might be built on top of a monthly_sales dbt model.

Creating the .yml File

Navigate to your dbt project directory. Create or open an existing .yml file where you'll define your exposures.

Defining the Exposure Properties

Here's a business-related example:

version: 2

exposures:
  - name: sales_dashboard_exposure
    type: dashboard
    owner:
      name: Marty McFly
      email: marty@FrisbiePieCompany.com
    depends_on:
      - ref('monthly_sales')
    description: Monthly sales dashboard used by the executive team.
    url: https://looker.company.com/dashboards/123
    maturity: high

Linking Exposures to dbt Models

The depends_on property links the exposure to its upstream dbt models. In our example, the Looker dashboard depends on the monthly_sales dbt model.

Working with Exposures in dbt

After defining exposures, you can reference them in the dbt CLI.

Run models feeding into an exposure:

dbt run -s +exposure:sales_dashboard_exposure

Test these models:

dbt test -s +exposure:sales_dashboard_exposure

Automating Exposures

While defining exposures manually is powerful, automation tools like AirOps can generate dbt exposures automatically after a data model is built, ensuring exposures are always up-to-date.

Visualizing Exposures in the dbt Docs Site

Generate your dbt docs with dbt docs generate and view them with dbt docs serve. Navigate to the exposures section, and you'll see a dedicated page for each exposure, complete with all the details you provided.

Best Practices for Using dbt Exposures

  • Regularly Update Exposures: As your data models evolve, ensure your exposures reflect these changes.
  • Maintain Clear Descriptions: This aids data consumers in understanding the purpose and context of each exposure.
  • Monitor Maturity Levels: As a dashboard or report moves from development to production, update its maturity level in the exposure.

Conclusion

dbt exposures offer a structured way to understand and document the downstream usage of your dbt models. By effectively using exposures, data teams can ensure transparency, traceability, and better communication with business stakeholders.

Additional Resources

database icon
The first SQL editor with built-in dbt Core ™
Simplified dbt development - Create and manage your dbt models and macros all in one place with PopSQL