Semantic layers for AI: one definition of every KPI

A semantic layer stores each business metric once, with its formula, filters, joins and owner, so dashboards and AI assistants all return the same number.

By CloudOEngine.ai Engineering · · 12 min read

A semantic layer is a single, shared set of metric definitions that sits between your raw tables and every tool that reads them. It records how "net revenue" or "active customer" is calculated (the formula, the filters, the time column, the joins and who owns it) so that a dashboard, a spreadsheet and an AI assistant asking the same question all get the same number. For AI it matters even more than for BI, because a model that writes its own SQL will otherwise invent a slightly different definition every time it is asked.

Four numbers for one question

As an illustration, take a Monday review at a consumer goods distributor. The head of sales says there were 4,180 active customers last month. Finance says 3,950. Operations has 4,410. All three are honest. Sales counts any customer who placed an order. Finance counts customers with an invoice that was not fully reversed by a credit note. Operations counts delivery addresses, so a retailer with two outlets is two customers.

Now the company adds an AI assistant over the warehouse, and the managing director types "how many active customers did we have last month?" The model reads the schema, sees an orders table and a customers table, and writes reasonable SQL. It produces a fourth number. Tomorrow, asked the same question in different words, it may join through invoices instead and produce a fifth.

Nothing here is a model failure in the usual sense. The SQL runs. The problem is that the definition of "active customer" lives in three people's heads and a few spreadsheet formulas, and the model has none of them. A semantic layer is where you write that definition down once, in a form both people and machines can read.

What the benchmark says about raw schemas

The cleanest evidence comes from a 2023 benchmark by Juan Sequeda, Dean Allemang and Bryon Jacob. They took an enterprise SQL schema from the insurance domain and wrote 43 business questions against it, ranging from simple reporting to metrics, and sorted them by how complex the question was and how many tables it needed.

GPT-4, given the questions and the SQL schema with no other context, answered 16.7% of them accurately. When the same questions were posed over a knowledge graph built on that database (an ontology describing the business concepts, plus mappings to the tables), accuracy rose to 54.2%.

The detail I find more telling is in the breakdown. For questions that needed a complex part of the schema, the SQL approach scored 0% in both categories. The paper notes that when a question needs more than five tables to answer, accuracy drops to zero.

A knowledge graph is not the same thing as a metrics layer, and the models in that paper are older than what you would choose today. But the lesson carries over. The improvement came from giving the model an explicit description of what the business concepts are and how they connect, instead of asking it to reverse-engineer that from table names. Our article on data catalogs for AI makes the same point about choosing tables; a semantic layer takes it one step further and fixes the calculation itself.

What goes into a definition

Different tools use different words, but they describe the same few parts. dbt's MetricFlow, which powers the dbt Semantic Layer, builds on semantic models made of entities, dimensions and simple metrics, then combines them into other metric types. Snowflake's semantic views use logical tables, relationships, facts, dimensions and metrics. Databricks calls its version metric views and describes them as separating measure definitions from the fields you group by, so a metric is defined once and can be sliced by any field.

Part What it means MetricFlow term Snowflake semantic view term
Business object The thing being counted: a customer, an order, a store Semantic model with entities Logical table
Join path How objects connect, through which keys Entities (primary, foreign) Relationships
Grouping field What you slice by: region, channel, month Dimensions Dimensions
Row-level value A number on each row before aggregation Expression in a simple metric Facts
Metric The aggregated, named business number Metrics (simple, ratio, derived, cumulative, conversion) Metrics

On top of the parts, every metric needs four decisions written down, and these are where the Monday argument above actually lives.

The first is the aggregation and its exact column: count_distinct(customer_id) or count_distinct(delivery_address_id). The second is the filter: only invoices that were not fully reversed, only orders not cancelled, only B2B channels. dbt's documentation describes a metric filter as "your WHERE clause", and lets a ratio metric apply a filter to the numerator only, the denominator only, or both. The third is the time column: is a sale counted on the order date, the invoice date or the delivery date? Pick one per metric and name it. The fourth is ownership: who can change the definition and who must be told when it changes.

A definition in YAML looks dull, and that is the point. As an illustration, "active customer" for the finance team might read: count distinct customer IDs on invoices dated in the period, excluding invoices with a credit note for the full amount, timed by invoice date, owned by the financial controller. Sales can keep its own metric too, but it gets a different name, such as ordering_customers, so nobody confuses the two again.

Writing the first drafts is the slow part, because someone has to look at the schema and work out which columns could plausibly be the business numbers. In CloudOEngine's data layer, AI reads your real data schemas to propose KPIs, which gives the metric owners a draft to accept, rename or reject rather than a blank page.

Orders database rows, not meaning Invoice files GST, credit notes Store visit counts from cameras Semantic layer Entities and join keys Dimensions and time grain Metrics with filters Owner, version, review Dashboards same number AI assistant asks by metric name Agents and alerts act on one definition Without it: each tool and each prompt rewrites the SQL, and the numbers drift apart
Sources feed one set of definitions. Dashboards, assistants and agents read metrics by name instead of each writing its own SQL.

Where hand-written SQL goes wrong

Most metric disagreements I would expect to find in an audit are not about the business definition at all. They are arithmetic mistakes that look fine in a single query and only show up when someone compares two reports. A model writing SQL makes exactly the same ones, faster.

Averaging ratios is the classic. As an illustration, Store A had 200 visitors and 50 buyers, a 25% conversion rate. Store B had 2,000 visitors and 200 buyers, 10%. Ask for "average conversion across stores" and a naive query averages the two rates to get 17.5%. The real figure is 250 buyers over 2,200 visitors, about 11.4%. A semantic layer avoids this by defining conversion as a ratio of two metrics, buyers over visitors, so both are totalled at whatever grain you ask for and divided last. MetricFlow, for example, has a ratio metric type that takes a numerator metric and a denominator metric rather than a pre-computed rate.

Fan-out joins are the second. Suppose shipping fees are stored once per order, and someone joins orders to order lines to filter by product category. An order with three lines and a ₹60 shipping fee now appears three times, and the shipping total for that order becomes ₹180 (again, an illustration). The SQL is valid and the number is wrong. dbt's documentation says MetricFlow records the type of each join key so it can steer queries to appropriate joins and avoid fan-out and chasm joins. Whatever tool you use, the join rules should belong to the layer, not to whoever writes the query that day.

The third is time. "Revenue in March" by order date and by invoice date can differ by days of trading at each month end, and a model has no way to know which one finance closes on. Fix one time column per metric. dbt's approach is to set the native grain of the time column (hourly, daily) and let the query roll it up to week, month or year, never to a finer grain than the data has.

The last is the quiet one: units and tax. Amounts in paise next to amounts in rupees, revenue with and without GST, gross of returns or net. Put the unit and the treatment into the metric's description, and put it in the name too if two versions must coexist.

Giving the AI metrics instead of tables

Once the definitions exist, change what the assistant is allowed to do. Instead of handing the model the warehouse schema and asking for SQL, give it a tool that lists the available metrics with their descriptions, and a second tool that queries a metric by name with a set of dimensions, filters and a time grain. The layer compiles the SQL. The model's job shrinks from writing a correct five-table join to picking active_customers, grouped by region, for last month.

That narrower job is one a model does well, and it fails in a visible way. If someone asks for a metric that does not exist, the right answer is "there is no defined metric for repeat purchase rate; the closest are X and Y", not a freshly improvised query. I would make that refusal a rule in the system prompt and test it, because an assistant that quietly falls back to raw SQL brings the Monday argument straight back. Our explainer on tool calling covers how to describe tools like these so the model picks the right one.

Show the definition with the answer. A reply that says "3,950 active customers (finance definition: distinct customers with a non-reversed invoice, by invoice date)" can be checked by the person reading it. A bare number cannot.

You also want a record of which metric the assistant asked for and with which filters, so that when a number looks odd you can tell whether the definition or the question was wrong. In CloudOEngine's AI runtime, agents run real tools and every step and tool call is traced and inspectable, so the metric query sits in the same timeline as the answer it produced.

Who is allowed to change a definition

A semantic layer turns a definition into shared infrastructure, which means a careless change now breaks every dashboard and every assistant at once. Treat definitions like code. Keep them in version control, require the metric owner to approve changes, and note the date a definition changed so that a jump in a trend line can be explained. When "active customer" changes from 90 days to 60, last quarter's board pack and this quarter's will not match, and someone will ask why.

Access is the other half. The layer can make a metric easy to query, but it should not make it easy for the wrong person to query. Margin by customer may be fine for the finance team and off limits for a sales assistant used by the whole field force. The rules that apply to the underlying tables have to apply to the metrics built on them, and to any AI that queries on a user's behalf. CloudOEngine applies one permission model and one audit trail across connected data, pipelines and agents, with role-based access included, so an agent querying data on a user's behalf sits under the same access rules and audit trail as everything else.

Lineage closes the loop: when a source column changes, you need to know which metrics depend on it before the numbers move. Our article on data lineage for AI covers how to record that.

Do you need to wait for a standard?

No, but it helps to know where the standards are heading. In September 2025 Snowflake and a group of partners announced the Open Semantic Interchange (OSI) initiative, which dbt Labs describes as an effort to create vendor-neutral standards for sharing semantic data across analytics and AI tools. On 14 October 2025, dbt Labs said it was open sourcing MetricFlow under the Apache 2.0 licence and called it "a central component" of the OSI vision. In January 2026 the first version of the OSI specification was published in an Apache 2.0 repository, covering datasets, metrics, dimensions, relationships and context. On 10 July 2026 the project was accepted into the Apache Incubator under a new name, Apache Ossie.

My reading: the format question is being worked on in the open, and moving definitions between tools should get easier. The harder work, which no standard does for you, is deciding what "active customer" means and getting finance and sales to sign the same page. Do that now, in whatever format your current tools accept, and keep the definitions plain enough to port later.

Where to start

If your company has no metric definitions written down today, this is the order I would follow:

  1. List the ten numbers that cause arguments in management reviews. Ignore everything else for now.
  2. For each one, write the aggregation, the column, the filters, the time column, the unit and the owner. Where two teams mean different things, give them two names.
  3. Model the entities and join keys those ten metrics need, and nothing more.
  4. Have each owner approve their definitions, and put them under version control.
  5. Point one dashboard and one AI assistant at the layer, with the assistant limited to defined metrics.
  6. Ask the assistant twenty real questions from last month's meetings and compare its answers to the numbers people used.

Step six is the one that tells you whether it worked. If the assistant and the finance team agree on all twenty, you have a semantic layer. If not, the disagreements show you which definition to fix next.

How CloudOEngine helps

CloudOEngine is one platform and one console for connecting data (databases, files and camera streams), building pipelines and running an AI runtime with an LLM gateway, agents with tool access and RAG, alongside Vision AI and live video. Everything sits under one permission model and one audit trail, which is what a shared set of metric definitions needs.

Getting the first definitions written is usually the bottleneck. CloudOEngine's AI reads your real data schemas to propose KPIs, so metric owners start from a draft based on the tables they actually have, and decide what to keep, rename or reject.

Data has to be connected before it can be defined. 500+ connectors bring databases and files into the same platform, and camera streams connect to it too, so the sources behind your KPIs are reachable from one console.

When an AI assistant answers a metric question, you need to see what it asked for. Agents run real tools, and every step and tool call is traced and inspectable, so a wrong number can be traced to the definition or the question.

Governance is included, not sold separately: tenant isolation, role-based access, audit logs and per-tenant encrypted secrets apply to agents as they do to people.

Book a demo or see the data layer.

Frequently asked questions

What is a semantic layer?

A semantic layer is a set of definitions that sits between your raw tables and the tools that read them. It records each metric's formula, filters, time column and join paths once, so every dashboard, spreadsheet and AI assistant computes the metric the same way.

Why does an AI assistant need a semantic layer?

Without one, the model writes fresh SQL for every question and has to guess what each business term means. In a 2023 benchmark on an insurance database, GPT-4 answered 16.7% of questions correctly over the raw SQL schema and 54.2% when the questions were posed over a knowledge graph that encoded business meaning.

Is a semantic layer the same as a data catalog?

No. A catalog helps people and agents find data and understand what tables and columns mean. A semantic layer fixes how each metric is calculated. The two work best linked, with each glossary term in the catalog pointing at the governed metric definition.

Which semantic layer formats are open?

dbt Labs open sourced MetricFlow, its metric engine, under the Apache 2.0 licence in October 2025. The Open Semantic Interchange specification, started by Snowflake and partners in September 2025, was released under Apache 2.0 in January 2026 and entered the Apache Incubator as Apache Ossie in July 2026.

How many metrics should a company define first?

Start with the ten or so numbers that are argued about in management meetings, not with every column in the warehouse. A small set of definitions that people have signed off is worth more than hundreds that nobody owns.

Sources

  1. Sequeda, Allemang and Jacob: A Benchmark to Understand the Role of Knowledge Graphs on LLM's Accuracy for Question Answering on Enterprise SQL Databases (arXiv 2311.07509, full text)
  2. dbt docs: About MetricFlow
  3. dbt docs: Creating metrics
  4. dbt Labs: Affirms commitment to Open Semantic Interchange by open sourcing MetricFlow (14 October 2025)
  5. dbt Labs: The OSI spec updates (29 January 2026)
  6. Apache Ossie (incubating): Updates
  7. Snowflake docs: Overview of semantic views
  8. Databricks docs: Unity Catalog metric views

#semantic layer #kpis #metrics #text-to-sql #data governance