Text-to-SQL Agents Are Breaking the Semantic Layer dbt Built
TL;DR — Semantic layers like dbt's metrics layer, Cube, and LookML exist to stop every tool from reinventing what 'revenue' means. Text-to-SQL agents skip that layer and query raw warehouse tables directly, which quietly recreates the exact metric-definition chaos semantic layers were built to kill. The fix is architectural: give the agent the semantic layer's API as its tool, not a raw SQL…
Semantic layers like dbt's metrics layer, Cube, and LookML were designed to prevent every tool from reinventing core metrics definitions. Text-to-SQL agents skip this layer and directly query raw warehouse tables, recreating the inconsistency that semantic layers were meant to eliminate. The solution lies in giving the agent access to the semantic layer's API rather than raw SQL connections to the warehouse.
When a natural-language agent interfaces with raw data, it independently computes metrics like revenue without considering factors like refunds, currency conversions, or trial account exclusions. This leads to unreliable, inconsistent results that were previously avoided with semantic layers. The issue is not malice or a design flaw in the models but architectural convenience.
The fix is not better prompting but a tool contract: instead of providing the agent with a SQL tool against the warehouse, give it access to the semantic layer's query API. This changes the agent's task to selecting from a bounded, reviewed vocabulary of metrics and dimensions, making the process more checkable and auditable. Semantic layers do not cover every long-tail question, so a tiered tool design is necessary: use the semantic layer for known metrics as the default and allow raw SQL generation as an explicit fallback.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.