Zero Labs
Industry News / AI

Why Semantic Layers Are Not Enough for Reliable Talk to Data Queries

Source · Towards AI By Supritin Ganguly

From the publisher’s feed, collected in the ZeroLabs newsroom.

How to fix Semantic models biggest blind spot using pre-query metadata enrichment.On a Tuesday morning, our data team set up a projector in the boardroom to demo our new natural language query interface built on Snowflake Cortex Analyst.The Chief Financial Officer sat at the head of the table and typed a test question:“What was our total software revenue in Germany last quarter?”Three seconds later, the screen rendered a crisp answer: $4.2M. with historical trends.The semantic model did its job. We had mapped standard synonyms (revenue to gross_revenue), set up metric dimensions, and written instructions to filter out test accounts. The CFO nodded, happy that the numbers matched our audited BI dashboards.Then the CEO took the keyboard and asked a six-word question:“How much did we bill Alphacorp?”The system processed the prompt, generated the SQL, and returned:Total Billed: $0.00The room went dead quiet. The CEO looked up and asked if we had somehow lost our biggest enterprise client overnight. We hadn’t. Our actual billing to that corporate group was well into eight figures. But our database did not contain a single customer record named "Alphacorp".Our billing system issued invoices to legal subsidiaries: NovaTech LLC, StreamNet Inc, Nova Cloud EMEA Ltd, and SecuriCore Inc. The connection linking those legal entities back to the parent brand lived inside our master account hierarchy — completely invisible to the flat semantic view and unreachable by standard Text-to-SQL.The Fundamental Blind spot of Semantic LayersSnowflake Cortex Analyst and similar natural language data tools rely on semantic models. You define tables, dimensions, metrics, relationships, and synonyms inside a semantic model configuration file.When a user asks a question, the LLM reads that semantic model, maps the user’s terms to columns and formulas, and compiles a SQL query.This setup works great for straightforward queries:Standard aggregations (“What was our ARR by region last quarter?”)Column filters (“Show me all enterprise-tier accounts in EMEA”)The system breaks down the moment business language diverges from how data is physically stored.Data stored physicallyWhen Cortex Analyst received "How much did we bill Alphacorp?", it did the only thing a semantic model knows how to do: it generated a pattern match on the customer name column.-- What the model generated without hierarchy contextSELECT SUM(b.invoice_amount) AS total_billedFROM analytics.fct_billing bJOIN analytics.dim_customer c ON b.customer_id = c.customer_idWHERE c.customer_name ILIKE '%Alphacorp%';Because no customer name literally contained "Alphacorp", the query returned empty rows. The model didn't fail at SQL syntax; it failed because it had no way to know that "Alphacorp" isn't a single customer record—it is an entire tree of accounts.Why Custom Instructions and Synonyms Cannot Solve ThisWhen teams encounter this issue, the initial reaction is to add more rules into the semantic model .Snowflake Cortex Analyst provides two main tools to guide the LLM:Synonyms and Descriptions: You can give a column nicknames (e.g., client_id can be called "customer", "account", or "buyer").Custom Instructions: You can supply text rules (e.g., “Always filter out internal test records” or “When users say ARR, calculate sum of mrr * 12”).These features handle column renaming and basic calculations well but This approach quickly falls apart in production.1. Context Window LimitsAn enterprise customer base or product catalog is large. If your company manages 5,000 corporate clients across 80,000 legal entities, you cannot paste that entire ownership tree into a static prompt without blowing past context limits and driving up token costs.2. Constant Data DriftCorporate structures change constantly. Mergers, acquisitions, spin-offs, and account reassignments happen weekly. Hardcoding entity relationships inside static configuration files guarantees that your numbers will silently drift out of date.3. Varying Tree DepthsA typical corporate tree has multiple layers. A static text rule cannot dynamically traverse varying branch depths on the fly. It cannot tell whether a user is asking about the entire worldwide parent or just a regional operating unit.Product catalogs have the exact same issue. An executive asking for "Beverage sales last month" expects a roll-up across hundreds of individual SKUs (SKU-001 Green Tea, SKU-042 Cold Brew). The transactions table stores SKU codes, not the word "Beverage". If the model writes WHERE product_name ILIKE '%beverage%', it returns zero.The Solution: A Pre-Query Metadata Enrichment LayerTo solve this without cluttering the semantic model, you need to separate entity resolution from SQL generation.Direct Path vs Context Enriched PathInstead of routing the user’s prompt straight to Snowflake Cortex Analyst, place a lightweight metadata enrichment layer in front of it. This layer intercepts the prompt, resolves parent entities into active leaf account IDs, and passes verified keys directly to Cortex Analyst.All you need in your warehouse is a single, clean Taxonomy Table. [ User Query ] "How much did we bill Alphacorp?" │ ▼┌──────────────────────────────────────────────────────────┐│ Pre-Query Enrichment Interceptor ││ ││ 1. Detects Entity Term: "Alphacorp" ││ 2. Traverses TAXONOMY Table ││ Alphacorp ──► NovaTech, StreamNet, Nova Cloud, Securi││ 3. Resolves to Primary Keys: ││ ['ACC-101', 'ACC-102', 'ACC-201', 'ACC-301'] │└──────────────────────────────────────────────────────────┘ │ ▼[ Enriched Prompt to Cortex Analyst ] "Calculate billed revenue for account IDs: ('ACC-101', 'ACC-102', 'ACC-201', 'ACC-301')" │ ▼┌──────────────────────────────────────────────────────────┐│ Snowflake Cortex Analyst ││ ││ Semantic View maps metrics & joins to fct_billing ││ Generates clean, deterministic SQL │└──────────────────────────────────────────────────────────┘ │ ▼[ Snowflake Warehouse Engine ] SELECT SUM(invoice_amount) FROM fct_billing WHERE ... │ ▼ [ Output: $18.4M ]A taxonomy organizes entities into parent-child trees. It answers: “What child accounts, subsidiaries, or SKUs roll up into this parent entity?”Schema StructureCREATE TABLE taxonomy ( taxonomy_id VARCHAR(50) PRIMARY KEY, domain VARCHAR(50), -- e.g., 'ACCOUNT', 'PRODUCT' parent_term VARCHAR(100), -- Parent Entity Name child_term VARCHAR(100), -- Subsidiary or Brand Name leaf_id VARCHAR(50), -- Target Primary Key in Fact Table level_number NUMBER);2. How the Data LooksAlphacorp (Parent Conglomerate) ├── NovaTech LLC [ACC-101] │ └── Nova Cloud EMEA [ACC-201] ├── StreamNet Inc [ACC-102] └── SecuriCore Inc [ACC-301]How the Resolution Flow Works at RuntimeWhen the CEO asks: “How much did we bill Alphacorp?”Step 1: The Interceptor checks the Taxonomy TableThe pre-query layer extracts "Alphacorp" and pulls all descendant leaf account IDs from taxonomy:JSON{ "requested_entity": "Alphacorp", "domain": "ACCOUNT", "resolved_account_ids": [ "ACC-101", "ACC-102", "ACC-201", "ACC-301" ]}Step 2: The Interceptor injects exact IDs into Cortex AnalystThe prompt sent to Cortex Analyst is transformed:“Calculate total billed revenue from fct_billing for account IDs: ['ACC-101', 'ACC-102', 'ACC-201', 'ACC-301']."Step 3: Cortex Analyst generates exact, deterministic SQLBecause Cortex Analyst receives verified primary keys instead of an ambiguous text string, it generates precise SQL against the semantic view:SQLSELECT SUM(b.invoice_amount) AS total_billed_amountFROM analytics.fct_billing bWHERE b.account_id IN ('ACC-101', 'ACC-102', 'ACC-201', 'ACC-301') AND b.invoice_status = 'PAID';Result: $18.4M instead of $0.00.Key TakeawayWhen an LLM writes SQL, a breakdown in business context won’t just throw a syntax error; it will return a clean, convincing, completely wrong hallucinated number. Semantic layers excel at joining tables and calculating metrics, but they fail when business questions rely on nested corporate or product hierarchies.By placing an metadata enrichment step in front of Snowflake Cortex Analyst, you give your users the ease of plain-English questions backed by the accuracy enterprise data requires.Why Semantic Layers Are Not Enough for Reliable Talk to Data Queries was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.