Skip to main content
Data Platform

Text-to-SQL for Enterprise Analytics: Schema Linking, Guardrails and Validating Against Governed Metrics

The demo is intoxicating: an executive types 'what was margin by region last quarter' and a chart appears. The problem arrives in week three, when two executives ask the same question, get two different numbers, and neither matches the board pack — because the model wrote two different SQL definitions of 'margin', and both ran. Text-to-SQL that is not anchored to a governed semantic layer does not democratise analytics. It industrialises disagreement.

Amit Kumar Singh - Technology Consulting Partner at MyData Insights

Technology Consulting Partner · MyData Insights

14+ years in industrial data · Former Accenture & EY · India, GCC, SEA

26 October 2026 · 11 min read

The bottom line

Natural-language-to-SQL is easy to demo and hard to trust, because the risk is not a query that errors — it is a query that runs and returns a plausible wrong number. Three things make it safe for enterprise use. Schema linking: the model must map question terms to the right tables and columns, which only works with curated metadata and descriptions, not raw column names. Guardrails: read-only access, row-level security, query cost and row limits, and allow-listed objects so a generated query cannot exfiltrate or overload. And validation against a governed semantic model — Power BI / Fabric measures — so 'margin' resolves to the one agreed definition rather than whatever the model invents. The honest limit: text-to-SQL is best over a curated semantic layer, not a raw warehouse, and ambiguous questions still need a human.

The danger is a confident wrong number

A text-to-SQL system that writes invalid SQL is a nuisance — the query errors and nobody is misled. The real danger is the query that is syntactically perfect, runs cleanly, and returns a number that is subtly wrong because the model guessed the wrong table, joined on the wrong key, or invented its own definition of a business term. No error is raised, a chart is produced, and a decision is made on it.

This is why enterprise text-to-SQL is a governance problem before it is a model problem. The question is not 'can the model write SQL' — modern models write SQL well — but 'can the organisation trust that the SQL means what the asker thinks it means'. The answer depends on three things the demo never shows: schema linking, guardrails, and validation against governed definitions.

Schema linking: mapping words to the right columns

Schema linking is the step where the model decides which tables and columns a question refers to. It is where most wrong-number failures originate. Point a model at a raw warehouse with columns called VAL1, DT_POST and ORG_CD and it will guess — sometimes correctly, sometimes not — and the guess is invisible in the output. Point it at curated metadata with clear names, descriptions, relationships and example values, and the mapping becomes reliable.

This is work you do once in the metadata layer, not per query: business-friendly table and column descriptions, documented relationships, synonyms for how people actually refer to things ('revenue', 'sales', 'turnover' resolving to the same measure), and sensible exclusion of columns that should never be queried. The quality of this metadata sets the ceiling on text-to-SQL accuracy far more than the choice of model.

Query guardrails: what the generated SQL may and may not do

A generated query must execute inside a cage. Non-negotiable guardrails: read-only credentials so no generated statement can ever write or drop; row-level security enforced at the data layer so the asker only sees rows they are entitled to, regardless of what the SQL requests; an allow-list of queryable objects so the model cannot reach into tables outside its remit; and cost and row limits so a careless cross-join cannot melt the warehouse or return ten million rows.

These controls live in the database and the serving layer, not in the prompt — a prompt instruction not to access the payroll table is a suggestion, while a permission that denies it is a control. Treat the language model as an untrusted query author whose output is always constrained by the same access rules you would apply to any user, because that is exactly what it is.

A prompt that says 'only query sales tables' is a request. A database role that can only read sales tables is a control. Enterprise text-to-SQL relies on controls, never on the model's good behaviour.

Validate against a governed semantic model

The fix for the two-executives-two-margins problem is to stop the model defining metrics at all. In a Microsoft estate the governed definitions already exist — as measures in a Power BI / Microsoft Fabric semantic model, where 'margin', 'OTIF' and 'fill rate' are defined once, version-controlled and agreed. Routing natural-language questions through that semantic model, rather than letting the model write raw aggregate SQL, means every answer uses the one sanctioned definition.

Where generated SQL is unavoidable, validate it against those definitions before it runs: check that the query's computation of a governed metric matches the certified measure, and reject or flag it if it does not. This turns the semantic layer into the source of truth and the language model into a translator from English to a question against that layer — which is the only version of text-to-SQL that survives contact with a board pack.

The architecture that actually works

The pattern that holds up in production is narrow by design: natural language in, resolved against curated metadata and a governed semantic model, executed under read-only, row-level-secured, cost-limited access, with the generated query and its assumptions shown to the user for transparency. On the Microsoft stack this is Conversational BI over a Fabric/Power BI semantic model, which is why Microsoft built Copilot for Power BI to work against the model rather than the raw lakehouse.

Showing the user the query and the definition it used is not a nicety — it is how trust is built and errors are caught. An analyst who can see 'margin = [Gross Margin] measure, filtered to Region = EMEA, FY2026 Q2' can confirm or correct it; a black-box number cannot be audited. The best systems make the generated logic visible by default rather than hiding it behind the chart.

Where this breaks

Text-to-SQL over a raw warehouse with poor metadata is where most enterprise attempts fail — the schema linking is unreliable and there is no governed definition to validate against, so the wrong-number risk is unmanaged. The capability belongs over a curated semantic layer; if that layer does not exist, building it is the real project, and text-to-SQL is the feature you add afterwards.

Ambiguous questions remain ambiguous. 'How are we doing in the north?' has no single correct SQL, and a system that silently picks an interpretation is back to inventing answers — the right behaviour is to ask a clarifying question, which is a product-design choice, not a model default. And highly complex analytical questions still exceed what any generator reliably produces, so text-to-SQL complements analysts on self-service questions; it does not replace them on hard ones.

What to do first

Anchor the capability to governance before you expose it to users.

  • Confirm a governed semantic model exists with the key metrics defined once (Power BI / Fabric measures) — build it if it does not; that is the real foundation
  • Curate the metadata the model links against: business-friendly names, descriptions, relationships and synonyms
  • Enforce read-only access, row-level security, object allow-lists and cost/row limits at the data layer, not the prompt
  • Route questions through the semantic model, and validate any generated SQL against the certified definitions before it runs
  • Show users the query and the definition used, and have the system ask rather than guess on ambiguous questions

Natural-language analytics is only trustworthy on top of a governed semantic model — without one, you are automating disagreement. Book 30 minutes with Amit on text-to-SQL done safely: schema linking, guardrails and validation against your Power BI and Fabric definitions. No slides, no pitch deck, no obligation to proceed.

Free Assessment

Where does your operation sit on the data maturity curve?

8 questions. 3 minutes. You get a scored breakdown across data infrastructure, analytics readiness, and automation potential — with a specific next step for your industry.

Data PlatformConversational BIPower BIMicrosoft FabricAzure OpenAIData Governance

Your Data · Our Technology · Our Automation

Get practical insights every fortnight

Amit writes about Microsoft Fabric, Power BI, AI in operations, and digital transformation for manufacturing and supply chain leaders. Practitioner perspective - no fluff, no vendor spin.

No spam. Unsubscribe any time. Also on Substack.

FAQ

Common questions

Why does enterprise text-to-SQL give inconsistent numbers?

Because the model defines metrics on the fly. If two questions about "margin" generate two different SQL computations, both run and both look valid, but they disagree with each other and with the board pack. The fix is to route questions through a governed semantic model where margin is defined once, so every answer uses the one agreed definition rather than the model's invention.

What is schema linking in text-to-SQL?

Schema linking is the step where the model maps the terms in a question to specific tables and columns. It is the main source of wrong-number failures: against a raw warehouse with cryptic column names the model guesses, often wrongly and invisibly. Curated metadata — clear names, descriptions, relationships, synonyms — makes the mapping reliable, and its quality sets the accuracy ceiling more than the model does.

How do you stop a text-to-SQL system from accessing data it should not?

With controls in the data layer, not instructions in the prompt. Read-only credentials prevent any write; row-level security ensures the asker only sees rows they are entitled to; an object allow-list stops the model querying tables outside its remit; cost and row limits prevent runaway queries. Treat the model as an untrusted query author constrained by the same access rules as any user.

Should text-to-SQL run over a raw warehouse or a semantic model?

A curated semantic model. Over a raw warehouse the schema linking is unreliable and there is no governed definition to validate against, so the wrong-number risk is unmanaged. Over a Power BI / Fabric semantic model the metrics are defined once and the model becomes a translator from English to a question against trusted definitions. If no semantic layer exists, building it is the real project.

Does text-to-SQL replace analysts?

No. It handles self-service questions over governed data well and frees analysts from routine report pulls, but ambiguous questions need clarification rather than a guessed interpretation, and complex analytical work still exceeds what any generator reliably produces. It complements analysts on the easy and medium questions; it does not replace their judgement on the hard ones.

Related FAQs

Questions operations leaders ask

Continue Reading

Related Articles

Data Platform

Microsoft Fabric vs a Legacy BI Stack (SSIS + SSAS + Power BI): The Migration Case

The most common estate I walk into is not a mess. It is an on-premises SQL Server, a set of SSIS packages built between 2014 and 2019, one or two SSAS cubes, and Power BI bolted on the front. It runs. Finance closes on it. The reason I get called is a symptom — the person who wrote the packages left, the overnight batch now finishes at 07:20 and the plant meeting is at 07:30. "It is old" is not a business case.

16 min read

Data Platform

Microsoft Fabric vs SAP Datasphere: Which One Do You Actually Need

The SAP account team says the analytics answer is SAP Datasphere, because that is where the business semantics already live. Two weeks later the Microsoft team says Fabric, because that is where Power BI, the MES extracts and the 3PL feeds already live. Both are internally consistent, and neither mentions the other except to dismiss it. The IT Head is asked to pick, and picks badly — because the two products solve different halves of one problem.

16 min read

Data Platform

The Hidden Costs of a Microsoft Fabric Migration Nobody Tells You About

The awkward conversation happens in month five, not month one. The platform works. The first three reports are live. Then the finance business partner circulates the actual run-rate against the approved business case, and the number is 30–50% over — not because the partner overran, but because six or seven cost lines were never in the case at all. I sell Fabric implementations. This names the costs my own proposals have to cover.

15 min read

Want to see how MDI solves this in your industry? Explore industry solutions

Sound like your estate?

Half an hour on your operation — what’s achievable, roughly what it costs, and whether it’s even worth doing. No deck.