{"slug": "beyond-the-semantic-model-composable-metrics-for-ai-agents", "title": "Beyond the semantic model: composable metrics for AI agents", "summary": "Databricks announced two new features in Unity Catalog Semantics that let AI agents, including those powered by Genie, compose independently governed metrics directly in SQL at query time: relationship constraints in Unity Catalog and query-time joins between metric views. The features build on Unity Catalog metric views, which Databricks released in April as a SQL-first way to define and govern business metrics, and separate governance of metrics and relationships from the scope of individual analyses. Databricks said the SQL engine itself now guards against join-induced duplication such as the chasm trap, so metric views can be joined with normal tables or other metric views rather than having to stand alone in the FROM clause.", "body_md": "Relationship constraints in Unity Catalog and query-time joins between metric views enable agents to discover and compose governed metrics directly in SQL\n\nby  [Chris Eubank](https://www.databricks.com/blog/author/chris-eubank), [Justin Talbot](https://www.databricks.com/blog/author/justin-talbot), [Chen Wang](https://www.databricks.com/blog/author/chen-wang), [Michael Zhang](https://www.databricks.com/blog/author/michael-zhang1)  and  [Can Efeoglu](https://www.databricks.com/blog/author/can-efeoglu) \n\nTraditional semantic models bring together the tables, relationships, and metrics needed to answer a set of business questions. This approach has worked well for BI, where the scope of analysis is often known when a model is built. But with AI agents, the scope of analysis is increasingly determined at query time. Users can ask questions spanning sales, support tickets, and product usage, even when the corresponding metrics are defined and governed independently by different teams. Anticipating every combination of metrics and dimensions at modeling time would require either unwieldy semantic models or a proliferation of redundant ones.\n\nAt Databricks, we’re taking a different approach to semantic modeling. In April, we [released Unity Catalog metric views](https://www.databricks.com/blog/redefining-semantics-data-layer-future-bi-and-ai), a SQL-first way to define and govern business metrics. Since then, many customers have adopted metric views as the foundation of their semantic layer.\n\nToday, we're excited to announce two new features in Unity Catalog Semantics that enable agents to compose independently governed metrics directly in SQL at query time:\n\nTogether, these features separate the governance of business metrics and relationships from the scope of individual analyses. Data modelers govern these definitions in Unity Catalog, while AI agents, including those powered by Genie, can combine them at query time to answer new business questions.\n\nA common problem in business analytics is combining metrics from different data sources. Suppose your company stores sales transactions and support tickets in two separate tables, but you want to consolidate them and view both broken down by region. A natural way to write this query in SQL would be to join the two tables on region, then compute the total sales amount and count all the support tickets:\n\nUnfortunately, this simple query can produce wrong results. If a region has multiple sales and multiple tickets, then the join duplicates sales and tickets, producing incorrect aggregates. This unexpected behavior is commonly referred to as *a chasm trap* and often trips up an unsuspecting user.\n\nTraditional semantic models address this problem by controlling how queries are constructed and how measures are evaluated. This typically requires users and tools to query through model-specific interfaces or drag-and-drop UI.\n\n[Unity Catalog Semantics](https://www.databricks.com/product/unity-catalog/business-semantics) takes a different approach: the protection against join-induced duplication is built into the SQL engine itself. Users, agents, and BI tools can construct rich SQL queries while relying on Databricks to preserve the correct aggregation semantics of governed measures.\n\nMetric views are like SQL views or tables, but they can include business metrics.\n\nThey have two kinds of columns:\n\nA measure can be as rich as the business requires, from SUM(amount) to ratios of other measures, running totals, and semi-additive balances. Measures are evaluated in SQL with MEASURE(), an aggregate function that goes anywhere an aggregate function goes: the SELECT list, HAVING, ORDER BY, subqueries, and CTEs:\n\nUnlike traditional semantic models whose semantics change dynamically based on the requested measures and dimensions, *a metric view preserves the relational behavior of a SQL view*. This means:\n\nPreviously you could query metric views in SQL, but a metric view had to be by itself in the FROM clause. Now you can join metric views with normal tables or views, or even with other metric views. The engine guarantees that joins do not inflate measures. Each source row contributes at most once per group, regardless of how many joined rows it produces; this is how we prevent chasm and fan traps.\n\nThis unlocks powerful analytic scenarios: flexible, on-the-fly analysis for users and agents, and reusable complex metric view source definitions for modelers.\n\nSuppose a colleague has created a metric view, *sales_metric_view*, with a *total_sales* measure and a *region* dimension. But you want to roll up sales to the country level. Rather than having to ask your colleague to add country to their metric view, you can join a geography table at query time:\n\nThe same pattern applies to joining fiscal calendars, customer attributes, and other business dimensions defined outside the metric view. You (or your agent) can extend an analysis using ordinary SQL without changing the governed metric view.\n\nYou can also join two metric views to analyze measures defined independently (perhaps owned by different parts of your organization). Let’s consider two metric views built on the following tables:\n\n**sales**\n\n| **sale_id** | **region** | **channel** | **sale_date** | **amount** | **cust_id** | \n| 1 | East | web | 2023-12-30 | 100 | 101 | \n| 2 | East | store | 2024-01-02 | 200 | 101 | \n| 3 | West | web | 2023-12-31 | 150 | 102 | \n| 4 | West | store | 2024-01-02 | 50 | 103 | \n| 5 | North | web | 2024-01-03 | 75 | 104 | \n\n**tickets**\n\n| **ticket_id** | **region** | **severity** | **c_id** | \n| 1 | East | high | 101 | \n| 2 | East | low | 101 | \n| 3 | East | low | 105 | \n| 4 | West | high | 102 | \n| 5 | West | low | 103 | \n| 6 | South | low | 106 | \n\nThe corresponding metric view definitions are below:\n\n*sales_metric_view*\n\n*tickets_metric_view*\n\nYou can now report sales and support tickets together by joining the two metric views:\n\n| **region** | **sales** | **sale_count** | **ticket_count** | \n| East | 300 | 2 | 3 | \n| West | 200 | 2 | 2 | \n\nThe key feature is that this join does not incorrectly duplicate measures. East has two sales and three tickets, producing six joined rows. A regular SUM(s.amount) over those rows returns 900, rather than 300. But MEASURE(s.total_sales) correctly returns 300, because each original sale contributes only once. Similarly, MEASURE(t.ticket_count) counts three tickets, not six joined rows. This holds for one-to-many, many-to-one, and many-to-many joins. Whichever side fans out, the Databricks engine ensures each source row contributes to its measure at most once per group.\n\nNote that North and South are excluded by the inner join, just as in ordinary SQL. MEASURE() protects against join-induced duplication without changing the semantics of the join itself.\n\nYou can also combine measures from different metric views in expressions. For example, to calculate support tickets per sale:\n\nEast has 1.5 tickets per sale, while West has 1.0.\n\nJoins also let you use fields from one metric view to filter measures from another. For example, to report sales by channel, but only for regions with at least one low-severity support ticket:\n\n| **channel** | **sales** | \n| web | 250 | \n| store | 250 | \n\nEast and West both have low-severity tickets, so their sales qualify. However, East has two matching tickets. A regular SUM(s.amount) across the joined rows would double-count East's sales, returning 350 for web and 450 for store. With MEASURE(), the engine preserves the original measure semantics and correctly returns 250 for each channel.\n\nThe same filtering semantics extend to OUTER JOINs, HAVING on evaluated measures, and EXISTS and IN subqueries across metric views.\n\nYou could achieve the same result manually using a semi-join or deduplicating the matching regions before joining. But those rewrites require query authors to carefully reason about join cardinality and aggregation for every query. With Unity Catalog Semantics, you get the right answer while writing simple, straightforward queries.\n\nToday, metric view authors can declare multi-fact measures in limited scenarios using definition-time one-to-many joins in the metric view YAML. Soon, support for SQL joins between metric views in the metric view source will enable more flexible multi-fact definitions while preserving relational semantics.\n\nQuery-time joins allow agents to safely compose governed metrics in SQL. But agents also need to know how metric views relate to one another. *Relationship constraints* allow data modelers to capture and govern these relationships directly in Unity Catalog, without prescribing which joins must be performed for a particular analysis.\n\nForeign key constraints already provide a familiar SQL mechanism for describing relationships between tables. However, they are designed around many-to-one relationships based on key equality, rather than the broader range of relationships needed for semantic modeling.\n\nRelationship constraints address these shortcomings. A relationship constraint is a named, directional link between metric views, with a declared cardinality (one-to-one, many-to-one, or even many-to-many) and a flexible join condition. Agents and BI tools can use these constraints to discover how metric views relate to each other.\n\nSuppose *sales_metric_view* and *tickets_metric_view* both expose a customer identifier, and a third metric view, *customers_metric_view*, holds customer attributes such as segment. The two facts meet at the shared dimension:\n\nA data modeler can add relationship constraints between these metric views to document how they semantically relate to each other:\n\nThese relationships will now appear in DESCRIBE TABLE EXTENDED on the metric views and in information_schema.table_constraints. A tool that reads these relationships can discover that sales and tickets connect through customers, and can write the join itself:\n\nNote that no semantic model combining sales, tickets, and customers had to be defined in advance. The individual metric views and their relationships are governed in Unity Catalog, and the agent determines which metric views to join based on the business question. The SQL engine preserves the aggregation semantics of each measure across those joins.\n\nWe plan to augment these constraints with more instructions to better address cases such as role-playing dimensions and resolving path ambiguity.\n\nRelationships complement the joins a metric view can declare in its own definition.\n\nA definition-time join in the metric view YAML *fixes the join at definition time*; the engine must use that join path. This is useful when there is exactly one way to relate two datasets, or when the modeler wants to lock in a cross-metric view measure definition using a specific path.\n\nA relationship constraint *describes possible joins but defers the choice to the agent or the user at query time*. This is useful when there are, or may eventually be, multiple possible ways to relate two datasets, for example, role-playing dimensions (a shipping city and a billing city), a self-relationship (employees and their managers), and even cycles. In these cases, the consuming tool can decide which joins best fit the analytic question at query time.\n\n[Genie Ontology](https://www.databricks.com/product/genie/ontology) already treats metric views as the authoritative definitions of business metrics. With relationship constraints, Genie can also discover how these independently governed metric views relate to one another.\n\nIn the sales and support tickets example above, Genie can discover the relationships through the shared customer dimension and generate SQL to analyze sales and support tickets by customer segment. Query-time joins ensure that neither measure is inflated by the join.\n\nAs teams publish new metric views and relationships to Unity Catalog, they expand the range of business questions Genie can answer without having to rebuild existing semantic models.\n\nGenie One, Genie Agents, and Genie Code can leverage relationship constraints and query-time joins to answer questions across independently governed metric views. [AI/BI Dashboards](https://www.databricks.com/product/business-intelligence/ai-bi-dashboards) can also import relationships defined in Unity Catalog, eliminating the need to redefine them for each dashboard. Relationships authored within dashboards can be published back to Unity Catalog, making them reusable across other dashboards and Genie experiences.\n\nBI tools generate SQL for analytic operations such as Top N filters, nested aggregations, and cross-filtering. Integrating with traditional semantic layers often requires BI tools to translate these operations into a model-specific query interface or disable functionality that the interface cannot express. With query-time joins, BI tools can continue generating SQL for these operations while delegating the evaluation of governed measures to Databricks.\n\nFor example, the query below, generated by a BI tool, uses a subquery to identify the top two regions by number of sales, then filters the main query to report total sales revenue by channel across those regions. This type of analysis can be difficult or impossible to express through a restricted semantic query interface. With Unity Catalog Semantics, the query runs as written, and the Databricks engine preserves the aggregation semantics of the measures in both the subquery and the main query.\n\nWe believe this first-class SQL support makes UC Semantics a uniquely appealing integration target for BI tools. We have started working on integrations with some BI vendors and are looking forward to announcing these in the near future.\n\nIf you are a BI vendor, please reach out; we’d love to work with you on integrating UC Semantics into your tools.\n\nQuery-time joins and relationships build on what UC Semantics already offers with metric views:\n\nOur next steps continue adding the power of data modeling to SQL. We are working toward declaring ad hoc measures directly in SQL, without requiring a YAML definition for quick explorations or small extensions to existing metric views. We are also working toward rich SQL extensions to control a measure's evaluation context, so that semi-additive logic and period comparisons can be expressed in SQL rather than configured around them.\n\nOur direction is to make governed metrics and relationships reusable across the full range of questions that users and agents ask. By bringing semantic modeling into SQL and Unity Catalog, we can govern metrics independently of the analyses that consume them. Teams define their business metrics once, without having to anticipate every question that will be asked of them.\n\nLast July, we open-sourced the core metric view and measure reference implementation in Apache Spark™ and Unity Catalog. We are now working to build on top of this foundation and add support for joining measures in SQL. In parallel, we’re excited to be a top contributor to industry standardization efforts such as Apache Ossie (Incubating) and its commitment to portable query semantics.\n\nQuery-time joins and relationship constraints are in Beta on Databricks Runtime 19 and above and on SQL warehouses. The [documentation](https://docs.databricks.com/uc-semantics/metric-views/user-joins) for joining metric views in SQL, relationships between metric views, and querying metric views walks through the examples in this post, and the TPC-H tutorial builds a complete metric view from sample data.\n\n**How is a metric view different from a semantic model?**\n\nA metric view is a Unity Catalog view that behaves like a regular SQL view, with the addition of governed measures. A traditional semantic model takes a different approach: it selects which tables to join based on the requested measures and dimensions, so the underlying set of rows can change from one question to the next. Different BI tools or query interfaces may interpret the same model differently and return different answers.\n\nMetric views avoid this problem by governing the measure logic while preserving standard SQL semantics for everything else. Rather than asking every BI tool to understand a new semantic model, metric views build on a common interface that BI tools already understand: SQL. The metric logic stays consistent regardless of which tool asks the question.\n\n**Do I need a primary key for MEASURE() to work across joins?**\n\nNo. Each measure carries the identity of its source rows, and MEASURE() aggregates over those rows without duplication, regardless of how the query joins them. Two source rows with identical values remain two rows; only the duplication introduced by the join is removed.\n\n**What is the difference between definition-time joins in YAML, relationships, and query-time joins?**\n\nA join in the metric view's YAML definition fixes the modeling path at definition time, which suits star and snowflake schemas. A relationship is metadata that records how two metric views relate without executing a join. A query-time join composes metric views in SQL for one question. The three work together: define a star via a definition-time join in YAML, describe the graph with relationships, and compose across it at query time.\n\n**Can BI tools use metric view joins today?**\n\nYes. BI tools can integrate with metric views through different mechanisms, depending on their query capabilities.\n\nTools with a pass-through aggregate function can call the governed measure directly. In Tableau, for example, a calculated field that wraps MEASURE() in [RAWSQLAGG_REAL](https://docs.databricks.com/aws/en/uc-semantics/metric-views/bi-tools#query-measures-in-tableau-with-pass-through-functions) sends the measure to Databricks, which evaluates it exactly as defined. The tool keeps generating its own SQL, so it can still leverage features like Top N filters, sets, and two-stage aggregations on top of metric views.\n\nPower BI works through [mirroring](https://www.databricks.com/blog/unity-catalog-metric-views-now-power-bi-one-unified-governed-semantic-layer-all-your-reporting). Databricks publishes each metric view into a Power BI semantic model as a table with matching Power BI measures in DAX, so reports can join across metric views in that model.\n\nSubscribe to our blog and get the latest posts delivered to your inbox.", "url": "https://wpnews.pro/news/beyond-the-semantic-model-composable-metrics-for-ai-agents", "canonical_source": "https://www.databricks.com/blog/beyond-semantic-model-composable-metrics-ai-agents", "published_at": "2026-12-03 17:15:48.987280+00:00", "updated_at": "2026-12-03 17:15:51.724097+00:00", "lang": "en", "topics": ["ai-agents", "ai-products", "structured-data", "artificial-intelligence"], "entities": ["Databricks", "Unity Catalog", "Unity Catalog Semantics", "Genie", "Chris Eubank", "Justin Talbot", "Chen Wang", "Michael Zhang"], "also_reported_by": [], "takeaway": "Metric views in Unity Catalog can now be joined with normal tables or other metric views at query time, with the SQL engine preserving correct aggregation semantics of governed measures via MEASURE() to prevent chasm-trap duplication.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/beyond-the-semantic-model-composable-metrics-for-ai-agents", "markdown": "https://wpnews.pro/news/beyond-the-semantic-model-composable-metrics-for-ai-agents.md", "text": "https://wpnews.pro/news/beyond-the-semantic-model-composable-metrics-for-ai-agents.txt", "jsonld": "https://wpnews.pro/news/beyond-the-semantic-model-composable-metrics-for-ai-agents.jsonld"}}