FDE Times dataFDE jobs open 932▼14 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 62Companies hiring 202Remote-friendly 24%Median US pay $201kTop hirer Databricks 92
中文VI

The newspaper of the Forward Deployed Engineer

Guides

Text-to-SQL can run without errors and still get revenue wrong

A schema cannot tell a model how finance calculates MRR, so define each metric once in a semantic layer that LLMs and reports share.

ShareLinkedInFacebookX

In brief

  • LLMs rarely write SQL with bad syntax. What they often get wrong is the join path, so the answer is incorrect and no error appears.
  • A semantic layer fixes definitions and join paths in advance, so a metric is calculated the same way every time, whether an LLM or a dashboard asks.
  • Route any metric bound for the board, an audit or a KPI through the semantic layer. Keep text-to-SQL for exploratory questions.
Monthly bar chart for a 12,000 USD annual plan. Summing order values puts 12,000 USD in month 1 and zero in months 2 to 12. Counting through the subscription table gives MRR of 1,000 USD in each of the 12 months. Both methods total 12,000 USD for the year; they differ only in how it is spread across months.
Taking the shortcut from orders to products drops the entire annual plan into January. Going through the subscription table spreads it evenly over 12 months. Source: worked example in the article (illustrative data).

A $12,000 annual plan, paid in full in January, is worth $1,000 of monthly recurring revenue. An agent that adds up orders will report $12,000, with tidy SQL that runs without errors. When the finance team’s report shows something quite different that afternoon, the Forward Deployed Engineer who deployed the agent is the one called into the meeting.

Almost every FDE who works on a project to query data in natural language will run into some version of this. The root cause lies outside both the model and the prompt: the definition of “revenue” was never written down anywhere a machine could read it.

This guide shows how to fix the problem at its source: define each metric once in a semantic layer, then have both the LLM and the customer’s reports use that definition.

Valid SQL can still answer the wrong question

The team at Omni describes the problem well. In their view, LLMs do not necessarily write bad SQL. The difficulty is that they write queries that look reasonable but carry the wrong meaning. Omni’s example is a question about MRR: the model joins the orders table directly to products, skips the subscription table, and returns the total order value. No error message appears.

Cube explains why models make this mistake: a warehouse schema does not say how your company defines revenue. A column named amount cannot tell you whether it holds cash collected, revenue recognized or money due each month. Those rules live in the heads of the finance team, in an Excel file, or in a view that only one person still remembers.

At the customer site, this is the FDE’s job: turning definitions from the words of business users into something a machine can run. The model will not do it for you.

One customer, two numbers

Consider a worked example with illustrative figures. Customer A buys a $12,000 annual plan and pays in full in January. Add up order values through the orders → products shortcut, and January shows $12,000 while the next eleven months show 0. Go through the subscription table, and MRR is 12,000 / 12 = $1,000 for each month of the year.

Both queries run, but only the second answers the question finance asked. A single annual plan has inflated January MRR 12-fold. If the customer has a few hundred such contracts, the error becomes very hard to spot by eye.

The second common error is fan-out. Suppose a $100 order has 3 line items. Join orders to order_items, then run SUM(order_total), and the result is $300, because the order total is repeated on every line. The dbt documentation calls this family of errors fan-out joins and chasm joins, and MetricFlow is designed to avoid them when it chooses join paths.

Define it once, call it by name everywhere

A semantic layer handles both errors by fixing the join path in the model. Omni reports that when the MRR question is asked again on a semantic layer, the join path is already defined, so the metric is calculated the same way every time. Cube takes the same approach: the agent queries named measures and dimensions instead of rebuilding business logic from table and column names.

In the dbt ecosystem, MetricFlow is the engine that does this. It sets the specification for defining semantic models and metrics, and it generates SQL from those definitions. Each semantic model has three parts. Entities are the join keys, the edges that connect models. Dimensions are the axes along which data is sliced. Metrics are built on top.

Here is an illustrative version for MRR. The exact syntax depends on your dbt version:

semantic_models:
  - name: subscriptions
    model: ref('fct_subscriptions')
    defaults:
      agg_time_dimension: billing_month
    entities:
      - name: subscription
        type: primary
        expr: subscription_id
      - name: customer
        type: foreign
        expr: customer_id
    dimensions:
      - name: billing_month
        type: time
        type_params:
          time_granularity: month
      - name: plan_tier
        type: categorical
    measures:
      - name: mrr_amount
        agg: sum
        expr: monthly_amount

metrics:
  - name: mrr
    label: Monthly Recurring Revenue
    type: simple
    type_params:
      measure: mrr_amount

The detail to notice is monthly_amount. Dividing annual plans by 12 already happens in the fct_subscriptions table, which has been reviewed and has an owner. From here, the LLM only needs to call mrr by billing_month and plan_tier. Finance’s dashboard calls the same metric, so the agent and finance no longer have a number each.

A visible error beats a silent one

In 2026, dbt Labs ran a benchmark of 11 questions on the ACME Insurance dataset, asking each question 20 times across several LLMs. The most memorable finding was the way each approach failed, more than its accuracy rate. Text-to-SQL failed with an answer that sounded plausible but was wrong. The semantic layer failed with an error message.

For an FDE, this difference matters a great deal. An error message prompts users to ask again or come to you. A wrong number that looks plausible can sit unnoticed in a board deck for a whole quarter.

The benchmark has limits. To get text-to-SQL to work, the authors loaded the entire schema into context, and they acknowledge that this is not feasible for larger datasets.

Atlan, in its summary of the benchmark, also notes that this is a vendor testing its own product. Treat the result as a pointer, and run your own evals on the customer’s data.

Nor does dbt’s advice force a choice between the two. For any number headed to the board, an audit, OKRs, KPIs or a weekly report, connect the LLM to the semantic layer. Keep text-to-SQL for ad hoc exploratory questions.

Where to start at the customer site

Do not begin by modeling the whole warehouse. Take the weekly KPI report or the most recent board deck and pick out the metrics that appear most often. That list is the scope of your first phase.

Next, sit down with the person who actually owns each definition, usually in finance or RevOps. Write the definition in words before writing any YAML, for example: “MRR divides annual plans by 12, excludes setup fees, and is recognized by billing month.” Record the name of the person who approved each definition.

Then write the semantic model and run the metric for several closed months. Compare each number with the customer’s current report. Where they differ, go back to the owner of the definition and ask. Do not guess.

Connect the LLM only once the numbers match. At that point, set explicit routing: questions that touch a defined metric go through the semantic layer, and only the rest go to text-to-SQL.

Common traps

The first trap is defining a metric by its column name. A revenue column in the warehouse is not necessarily revenue as accountants understand it. The second is silently falling back to text-to-SQL when the semantic layer returns an error. Doing so throws away the semantic layer’s greatest advantage: errors surface instead of lying hidden.

The third trap is letting the LLM create new metrics at runtime. A new metric should go through code review like any other change. The last is trusting a vendor benchmark without an eval set of your own, made up of the customer’s real questions, each paired with an answer finance has confirmed.

How should this skill appear on your résumé?

When you read job descriptions for FDEs or solutions engineers, look for keywords such as dbt, MetricFlow, Cube, semantic layer or “metrics definitions”. They signal that the company needs someone to keep the numbers right as well as someone to connect an LLM to a database.

On a résumé, a line such as “standardized core KPI definitions in a semantic layer and reconciled them with finance reports before opening access to agents” carries far more weight than “built a text-to-SQL chatbot”.

LLMs will get better at writing SQL. Finding out how a customer calculates revenue will still mean asking people, then recording the answer in one place.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
4 sources
Read next on the roadmap · Stage 2: Broad engineeringA pod that keeps restarting with empty logs is not a dead endA five-step kubectl routine separates application bugs from infrastructure faults when a customer's cluster throws CrashLoopBackOff, OOMKilled or DNS errors.