Overview
Five blocks, one file
A dbt semantic model is a YAML object that sits next to a dbt model and declares five things:
- Name & description — the business name (
orders). - Model reference —
model: ref('fct_orders'). - Entities — the keys this model can join on. Each entity has a
type:primary(this is the table's PK),foreign(an FK to another semantic model), orunique. - Measures — numerical aggregates: a
name, anexpr(SQL), and anagg(sum,count,avg,count_distinct,max,min,median,percentile). - Dimensions — categorical or time columns the metric can be sliced by. Time dimensions also declare
type_params: { time_granularity: day }.
Why this shape is the right shape
It maps cleanly to dimensional modelling (facts ↔ measures, dims ↔ dimensions) but with added type-safety: the engine knows which entities are primary vs foreign, so it constructs join paths automatically and fails loud when a request asks for a join that does not exist.
Once a semantic model exists, metrics live in their own file (metrics.yml) and reference measures by name. That separation is the dbt SL's biggest win: the model is the stable artefact, metrics are the changeable, opinionated view on top.