| Customer | Active account | Fulfilled orders |
|---|---|---|
| A | Yes | 20 Aug 2026 |
| B | Yes | None, one pending order |
| C | No | 20 Nov 2026 |
| D | Yes | 2 Sep 2026 and 25 Nov 2026 |
Semantic Layer: Why AI Agents Get Business Metrics Wrong
An AI agent can write valid SQL and still report the wrong business metrics. The outcome depends on how business definitions are modelled, exposed and tested.

Author: Aleksandar Basara · Managing Director
Key points
- Valid SQL can produce a result that is wrong under the intended business definition.
- Semantic data models make business rules and metrics reusable across applications.
- An additional semantic layer platform is not always necessary.
- AI agents need acceptance tests against defined business results.
Who is our biggest customer this year?
A sales director might answer in terms of bookings, while finance looks at recognised revenue. Both use company data, yet they may arrive at different answers.
A semantic layer provides the business definitions, calculation rules and relationships that applications need to answer such questions consistently. It becomes particularly relevant when AI agents access the same enterprise data as established BI systems.
Before an agent can calculate a metric, somebody has to establish what that metric means.
Valid SQL can produce the wrong answer
Suppose a company wants to know how many active customers it has. The customer table contains a column called is_active. A language model could reasonably use it as a filter.
Sales, however, defines an active customer as someone with at least one fulfilled order in the preceding 90 days.
A small synthetic dataset illustrates the consequences. We use 1 December 2026 as the reference date and consider the 90 complete calendar days preceding it.
Query based on account status
An agent relying on account status might generate the following SQL query:
SELECT
COUNT(*)
FROM
customers
WHERE
is_active = TRUE;
Query based on the business definition
The result is 3 customers. Applying the sales team's business definition changes the query.
SELECT
COUNT(DISTINCT customer_id)
FROM
orders
WHERE
status = 'fulfilled'
AND fulfilled_at >= '2026-09-02'
AND fulfilled_at < '2026-12-01';
The result is now 2 customers.
Both queries were run in SQLite for this example. They are technically valid but answer different questions. Customer C has no active account, yet meets the business definition. Customer D has two fulfilled orders but must only be counted once.
A more capable language model can recognise and explain both interpretations. Without an authoritative definition, however, it has no reliable basis for choosing between them.
If that customer count feeds a sales analysis, forecasting model or management dashboard, the original misinterpretation can carry through to downstream processes.
What a semantic layer actually does
A semantic layer is a logical abstraction between data storage and the applications that consume it. It represents enterprise data through business concepts and makes defined metrics reusable.
The underlying semantic data model describes entities such as customers, orders and products, their relationships, and the rules for filtering and aggregation.
For the active customer metric, the model would need to specify:
- Which customer identifier is used.
- Which order status qualifies as fulfilled.
- Which date field determines the relevant event.
- How the time window is calculated.
- The level of granularity at which customers are counted.
The business definition can then be connected to an executable model. Applications can request the metric through an appropriate query interface without recreating its calculation every time.
This matters even more for complex metrics. Average order value requires different aggregation logic from revenue. A ratio cannot simply be averaged across regions. Joining orders to multiple line items at the wrong grain can multiply the order value.
These are data modelling problems. A semantic layer can describe valid relationships and calculations; its effectiveness depends on how consuming applications implement those rules.
Put business logic where it can be reused
For a company with a single BI system, defining metrics within that system may be an economically sound choice.
Things change when the same metrics are needed in a customer portal, an internal application or an AI agent.
If every application implements its own calculation, each change must be made and tested several times. Coordination becomes harder with every additional consumer, particularly when existing systems already disagree on the calculation.
One option is to expose the business models independently of the user interface. A headless semantic layer allows applications to access shared metrics through suitable APIs, SQL interfaces or dedicated query functions.
An agent might request active_customers for a specified period. The query interface can validate the parameters and enforce permissions before executing the underlying model.
The language model still has an important job: interpreting the question, selecting a suitable metric and communicating the result. The calculation itself can take place outside the model in a controlled environment.
Direct text-to-SQL can still be useful for exploratory questions. For authoritative business metrics, we would favour approved calculation models.
Whether that warrants independent semantic infrastructure should be decided as part of the wider data strategy.
How semantic models, glossaries and data platforms fit together
Implementation involves three distinct responsibilities: defining a business term, formally modelling it and executing the calculation.
Open-source technologies such as Apache Ossie and OpenMetadata illustrate how those responsibilities can be distributed across components.
Apache Ossie: exchanging semantic models
Apache Ossie, originally known as Open Semantic Interchange, develops an open specification for semantic models.
It describes datasets, fields, relationships and metrics, among other elements. Additional context can help AI systems interpret business terms and select appropriate queries.¹
The interesting aspect is the aim of reducing dependence on individual analytics platforms. Semantic models should be exchangeable between compatible systems.
Ossie is a specification. An execution implementation still has to interpret the model, generate calculations and resolve its relationships correctly. A YAML or JSON file alone does not do that.
OpenMetadata: ownership of business definitions
A business glossary records what an organisation means by its business terms.
OpenMetadata allows teams to describe terms, associate them with data assets and assign responsible individuals or teams. Reviewers can participate in approval workflows.²
For active customers, sales could own the business definition while the data team owns its technical implementation.
This division of responsibility matters when rules change. Moving the window from 90 to 120 days is a business decision first. Only then should it be reflected in the executable model.
dbt and Git: business rules as engineering artefacts
Much of the technical groundwork already exists in the transformation models of a data platform.
dbt supports the development, documentation and testing of data models. Its Semantic Layer extends this approach with MetricFlow for semantic modelling and querying.³
An organisation can version its business definitions, semantic models and transformations together. Git and a suitable CI/CD process provide a traceable foundation.
Changes must be coordinated across the components. Otherwise an updated SQL calculation may already be in production while the glossary and agent still use the previous definition.
We have explored the role of open data infrastructure in our OpenLakeForge review. It illustrates how storage, processing and governance can be combined in a shared platform. Its suitability for production requirements needs individual assessment given the alpha development status.⁴
When is a dedicated semantic layer worth it?
Not every company needs additional infrastructure for semantic modelling. The architecture depends on the number of consuming applications, the complexity of calculations and the systems already in place.
| Architecture | Suitable when | Limitation |
|---|---|---|
| Semantics within a BI system | Metrics are primarily used within an existing BI ecosystem | Reuse outside that system must be assessed |
| SQL views and curated data models | There are relatively few metrics and their calculations are stable | Flexible filters, aggregations and access rules may require additional development |
| Headless semantic layer | Several BI systems, applications and AI agents need shared metrics | An additional interface must be developed or integrated and maintained |
| AI agent with direct text-to-SQL | Exploratory questions need flexible answers | Business validation and controlled data access are particularly important |
These approaches can coexist. A company could expose existing SQL views for authoritative metrics while allowing an AI agent to perform exploratory analysis.
For a single use case, we would first assess whether existing data models and controlled query functions can supply the required metrics. An additional platform becomes interesting when business logic spreads across applications or existing interfaces cannot provide the necessary flexibility.
Retrieval-augmented generation can also play a role. A RAG system might supply the internal active customer definition or documentation of the financial year.
The resulting SQL must still respect the intended filters, relationships and permissions. For authoritative metrics, combining retrieved knowledge with executable, testable calculation models is often appropriate.
Who can change what a metric means?
Once metrics are shared across an organisation, modelling becomes an organisational question as well as a technical one.
Imagine sales extends the active customer definition from 90 to 120 days. The change could affect reporting, customer segmentation and automated processes.
What happens to historical metrics? Are previous reports recalculated under the new definition, or are both versions retained so a definition change is not mistaken for a change in customer behaviour?
A business owner needs to make that decision. The data team must determine how to implement and test the new definition. Affected applications need a controlled way to adopt it.
Access is equally important. A correctly defined metric can contain confidential information. An agent operating on behalf of a user must not automatically gain access to all the underlying data.
Permissions need technical enforcement at query interfaces and data sources. Instructions in a system prompt or business glossary cannot replace those controls.
This connection between business accountability and technical enforcement is central to data governance for AI.
How do you test an analytics agent for business correctness?
For acceptance testing, we would start with a set of questions whose correct business answers are established before introducing the language model.
The tests need a defined data snapshot, metric versions and expected results. Alongside straightforward analytical tasks, they should cover ambiguous questions and company-specific exceptions.
For our customer example, part of the test suite might look like this:
| Test question or failure case | Expected behaviour |
|---|---|
| How many customers were active in the past 90 days? | Use the approved customer definition |
| A customer has multiple fulfilled orders. | Count the customer only once. |
| An order falls exactly on the lower time boundary. | Include it according to the defined time logic. |
| An order has been recorded but not fulfilled. | Exclude it from the active customer metric. |
| Who is our biggest customer? | Apply an authoritative definition or ask for clarification if ambiguous. |
| A user requests confidential customer data. | Technically enforce that user's access permissions. |
| A metric changed after deployment. | Use the intended model version. |
These tests should check both the calculation and the agent's selection of the metric.
It is useful to classify failures separately. Did the agent misunderstand the question? Did it select the wrong metric? Did the query engine use an inappropriate join? Or was the calculation correct but the language model misrepresented the result?
The better those failures are distinguished, the easier it is to improve the right part of the system. An aggregate answer-quality score alone would leave the underlying component unidentified.
In production, the metrics, model versions and executed queries should also be traceable. We discuss the wider operational requirements in our article on observability and evaluation of production AI agents.
Start with the metrics that drive decisions
Introducing a semantic layer does not require modelling all enterprise data at once.
Start with metrics shared by several teams or applications where differing interpretations have meaningful business consequences.
Define the business owner, calculation, data lineage and intended access for each metric. Then use concrete applications to determine whether the existing architecture is sufficient or needs extending.
Through our Data & AI Engineering work, we develop data models, integration interfaces and AI applications around actual business requirements. That includes determining which existing systems can be retained.
Sources
1. Apache Software Foundation: Apache Ossie – Core Specification. Ongoing project documentation, accessed 1 December 2026.
2. OpenMetadata: How to Create Glossary Terms. Documentation v1.12.x, accessed 1 December 2026.
3. dbt Labs: Semantic Models and Quickstart for the dbt Semantic Layer. Accessed 1 December 2026.
4. OpenLakeForge: Project documentation and repository. Accessed 1 December 2026.
Data & AI Engineering
Discuss your data architecture
We assess which metrics need to be shared and how their business logic can be exposed through your data platform and AI applications.
Aleksandar Basara
Managing Director
aleks@valanor.co
+49 (0) 711 16 44 6 83
Lindenspürstrasse 22, 70176 Stuttgart
