All skills
dbt-labs avatar

/building-dbt-semantic-layer

@f8d7828 official
by dbt Labsdbt-labs/dbt-agent-skills729 stars
62

Use when creating or modifying dbt Semantic Layer components — semantic models, metrics, dimensions, entities, measures, or time spines. Covers MetricFlow configuration, metric types (simple, derived, cumulative, ratio, conversion), and validation for both latest and legacy YAML specs.

Use this Skill: https://skilld.dev/gh/dbt-labs/dbt-agent-skills/building-dbt-semantic-layer

This session only. Nothing lands on disk.

referencesbest-practices.md

≈867 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Semantic Layer Best Practices

Synthesized from the dbt Semantic Layer best practices guide.

Core Principles

  1. Prefer normalization - Let MetricFlow denormalize dynamically for end users rather than pre-building wide tables
  2. Compute in metrics, not rollups - Define calculations in metrics instead of frozen aggregations
  3. Start simple - Build simple metrics first before advancing to ratio and derived types

Semantic Model Design

Entities

  • Each semantic model needs exactly one primary entity
  • Use singular naming (order not order_id) with expr for the column reference
  • Foreign entities enable joins between semantic models

Dimensions

  • Always include a primary time dimension when the model has metrics or measures
  • Set granularity appropriately for time dimensions
  • Use computed expressions for derived dimensions (e.g., categorizing by thresholds)

Measures (Legacy Spec) / Simple Metrics (Latest Spec)

Legacy spec (dbt Core 1.6-1.11):

  • Create measures for quantitative values you'll aggregate
  • Use expr: 1 with agg: sum for counting records
  • Measures are the building blocks for all metric types
  • Define components consistently: entities -> dimensions -> measures

Latest spec (dbt Core 1.12+ / Fusion):

  • Define simple metrics directly on the model for quantitative aggregations
  • Use expr: 1 with agg: count or agg: sum for counting records
  • Simple metrics are the building blocks for advanced metric types
  • Define components consistently: entities (on columns) -> dimensions (on columns) -> simple metrics

Metric Design

Required Properties

Every metric needs: name, description, label, and type

Type Progression

  1. Simple - Single aggregation with optional filters (start here)
  2. Ratio - Numerator divided by denominator
  3. Derived - Calculations combining multiple metrics
  4. Cumulative - Running totals or windowed aggregations

Naming

  • Use clear business-friendly labels for downstream tools
  • Use double underscores to disambiguate dimensions (orders__location)

Development Workflow

# Refresh manifest after changes
dbt parse

# List available dimensions for a metric
dbt sl list dimensions --metrics <metric_name>   # dbt Cloud CLI / Fusion CLI when using the dbt platform
mf list dimensions --metrics <metric_name>       # MetricFlow CLI

# Test metric queries
dbt sl query --metrics <metric_name> --group-by <dimension>
mf query --metrics <metric_name> --group-by <dimension>

What to Avoid

Anti-pattern Better approach
Building full semantic models on dimension-only tables Pure dimensional tables only need a primary entity defined
Refactoring production code directly Build in parallel, deprecate gradually
Pre-computing rollups in dbt models Define calculations in metrics
Creating multiple time dimension buckets Set minimum granularity, let MetricFlow handle the rest
Mixing legacy and latest spec syntax in the same project Pick one spec and use it consistently

When to Use Marts

Use intermediate marts strategically for:

  • Grouping related tables
  • Attaching metrics to dimensional tables
  • Complex joins that benefit from materialization

Build semantic models on staging when source data is already well-structured.

Source: SKILL.md on GitHub

1 warning17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill provides comprehensive guidance for authoring dbt Semantic Layer configurations across different specification versions. It includes best practices, implementation workflows, and validation steps using standard dbt tools and first-party utilities from dbt Labs. No security issues were detected.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer7mo

    1/5 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at f8d7828. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 3 months ago
user-invocable
false
metadata
{
  "author": "dbt-labs"
}
  • dbt
  • semantic-layer
  • metricflow
  • metrics
  • dimensions
  • entities
  • yaml
  • dbt-core

README badge

README badge for dbt-labs/dbt-agent-skills/building-dbt-semantic-layer

Guides the creation and modification of dbt Semantic Layer components—semantic models, entities, dimensions, and metrics—across both legacy (dbt Core 1.6–1.11) and latest (dbt Core 1.12+) YAML specs. Covers metric types (simple, derived, cumulative, ratio, conversion), MetricFlow validation, and common configuration pitfalls.

Generated from the current SKILL.md.

What dbt Core versions does this skill support?
The skill covers both latest spec (dbt Core 1.12+ and Fusion) and legacy spec (dbt Core 1.6–1.11). Projects on Core 1.12+ can use either spec; older versions must use legacy spec.
Does this skill help migrate from legacy to latest semantic layer spec?
The skill mentions the migration path via `uvx dbt-autofix deprecations --semantic-layer` and references a migration guide, but does not automate the upgrade itself—it guides manual authoring in either spec.
What validation tools does this skill use?
The skill uses `dbt parse` (or `dbtf parse` for Fusion) for YAML syntax, and `dbt sl validate` or `mf validate-configs` (MetricFlow CLI) for semantic layer validation. Both must pass before work is complete.
Can I use raw table columns in metric filters?
No. Filter expressions can only reference columns declared as dimensions or entities in the semantic model. Raw columns that aren't defined as dimensions cannot be used in filters, even if they appear in a measure's expression.
Does this skill handle time-based metrics?
Yes. The skill covers cumulative, ratio, and conversion metric types that require time dimensions, and references a separate time spine setup guide for time-based aggregations.

Generated from the current SKILL.md. These answers refresh after source changes.