dbt semantic layer
In development (August 2026). The catalog, validator, and compiler
surfaces described here are landing now; treat details as
subject-to-change until this notice is removed. Warehouse execution is
default-off behind ALPHASWARM_DBT_SEMANTIC_LAYER_ENABLED.
In plain English: today, answering "what was the average daily dollar volume for AAPL last quarter?" requires someone (or some agent) to hand-write SQL — and two people can write two different queries that give two different answers. A semantic layer fixes that by defining each business metric once, in a reviewed file, with its exact formula. From then on, everyone — dashboards, operators, AI agents — asks for the metric by name and gets the same governed calculation.
What it is
A dbt-MetricFlow-style metrics catalog, committed as YAML in the
alphaswarm repo, plus a local compiler that turns a metric request
into SQL without calling out to any external service:
- Semantic models —
alphaswarm/data/dbt/projects/core/models/metrics/semantic_models.ymldeclares entities, dimensions, and measures over warehouse tables (for exampleequity_minute_barswith volume, dollar-volume, and VWAP measures), with a daily time spine (models/semantic/time_spine_daily.sql). - Compiler & procedure —
alphaswarm/data/dbt/semantic/holds the catalog loader, aFilterBuilder, time-grain coarsening helpers, aLocalSemanticCompiler(simple / ratio / derived metrics → dbt-inline SQL), and aSemanticLayerProcedure(parse → validate → compile → optionally execute).
Design decisions worth knowing
- The legacy
semantic_models:spec is the single source of truth; dual-writing the newer nested MetricFlow spec is forbidden. - The production compile path is local — no
dbt-semantic-interfacesversion bump forces fat images. MetricFlow proper is an opt-in escape hatch viapip install 'alphaswarm[dbt-semantic]'(a dedicated extra, deliberately excluded from thefullanddata-fabricextras). - Catalog / validate / compile are read-only and always available; only warehouse execution is flag-gated, and the read paths never touch QuestDB.
Surfaces
| Surface | What it does |
|---|---|
data.dbt.list_metrics (MCP) | Enumerate the metric catalog with definitions. |
data.dbt.compile_metric (MCP) | Compile a metric + filters + grain to SQL without executing. |
data.dbt.query_metric (MCP) | Compile and execute against the warehouse (flag-gated). |
GET /dbt/semantic/catalog | The catalog over HTTP. |
POST /dbt/semantic/validate | Validate a metric request. |
POST /dbt/semantic/compile | Compile a metric request to SQL. |
For agents this pairs naturally with the Query data via MCP recipe: prefer a named metric over raw SQL whenever one exists.
Flags
| Flag | Default | Effect |
|---|---|---|
ALPHASWARM_DBT_SEMANTIC_LAYER_ENABLED | off | Gates warehouse execution only (data.dbt.query_metric). Catalog/validate/compile stay available. |
dbt var alphaswarm_semantic_layer_enabled | false | Keeps dbt build from materializing the time spine until enabled. |
See also
- Layer composition — how data layers stack.
- Query data via MCP — agent-facing data access patterns.
- Dataops: Airbyte + Dagster runbook — the orchestration side of the dbt projects.