# Text-to-SQL, Fixed Queries or a Semantic Layer: What's More Reliable?

> For numbers people act on, vetted queries or a semantic layer are more reliable than freely generated SQL. Free text-to-SQL suits exploratory questions that a person checks. Most production setups use a hybrid: vetted queries first, free SQL only as a clearly labelled fallback.

Canonical URL: https://www.ruebstudio.de/en/guides/ai-agent-integrations/text-to-sql-vs-semantic-layer  
Author: Dr.-Ing. Marcus Rüb, CEO  
Published: 2026-11-24

An AI agent that answers questions from a database can get to SQL in three ways. It can write the query itself, pick one from a catalogue of vetted queries, or ask a semantic layer that defines metrics centrally. The basics of a safe connection are covered in [Connecting an AI Agent to Databases](https://www.ruebstudio.de/en/guides/ai-agent-integrations/connect-ai-agent-to-database). This guide tackles the next decision: which route gives numbers you can trust, especially on ERP schemas with cryptic column names?

## The short answer: which approach fits when?

If a number drives a decision, such as revenue, margin or overdue invoices, use vetted queries or a semantic layer. Free text-to-SQL is good at one-off exploratory questions but needs a review step. Most production systems combine the three in a tiered hybrid rather than picking one.

In brief:

- **Fixed queries** when a small set of recurring questions must be answered exactly and the schema is hard to read.
- **A semantic layer** when many tools and people use the same metrics and the definitions must not drift.
- **Free text-to-SQL** when questions are open-ended, someone checks the output, and a wrong answer is cheap.

## How accurate is free text-to-SQL in practice?

Language models score well on academic benchmarks and much lower on realistic enterprise data. The gap comes from huge schemas, messy values and business knowledge that is not in the database. For unreviewed metrics, today's accuracy is not good enough.

The figures (as of November 2026):

- On BIRD, humans reach 92.96% execution accuracy, and the top overall score on the [BIRD leaderboard](https://bird-bench.github.io/) in October 2026 was 83.40%. Even the leader gets roughly one question in six wrong.
- The [BIRD paper](https://arxiv.org/abs/2305.03111) names three core difficulties: dirty database contents, external knowledge linking the question to the data, and SQL efficiency.
- [Spider 2.0](https://arxiv.org/abs/2411.07763) uses real enterprise workflows on databases that often have more than 1,000 columns. According to its abstract, an agent built on o1-preview solved only 21.3% of tasks, compared with 91.2% on Spider 1.0 and 73.0% on BIRD.

For an ERP system, Spider 2.0 is the more honest yardstick. Many ERP tables carry abbreviated column names that have grown over years of customisation. Whether a field holds net or gross, whether cancelled documents count, which date is the posting date: none of that is in the schema. The model guesses, and a wrong guess produces SQL that runs cleanly and returns a plausible but wrong number. That silent failure is the core risk.

## Comparison table: three approaches, side by side

The approaches differ mainly in where business knowledge lives: inside the model, in reviewed SQL, or in a central definitions layer. Error risk, coverage and upkeep all follow from that. The table summarises the trade-offs for an agent working against an ERP schema.

| Criterion | Free text-to-SQL | Fixed queries | Semantic layer |
|---|---|---|---|
| Error risk on cryptic schemas | high, silent errors possible | low, SQL is reviewed | low, joins and filters are defined |
| Coverage of new questions | very broad | catalogued questions only | any combination of defined metrics and dimensions |
| Metric consistency | varies with phrasing | high, but maintained per query | high, one definition for every tool |
| Upkeep after schema changes | nothing to update, but breaks go unnoticed | update every affected query | update the definition once |
| Effort to start | low | low to medium | medium to high |

## Free text-to-SQL: strengths and weaknesses

Free text-to-SQL can answer questions nobody anticipated and needs little upfront work. Its correctness, though, depends on schema descriptions, examples and review. Without them, silent errors on ERP data are likely, and the same question phrased differently may return a different figure.

**Strengths:**

- Flexible for ad hoc analysis and data exploration.
- Quick to prototype: schema metadata and a read-only connection are enough.
- No catalogue to maintain.

**Weaknesses:**

- Different wording can produce different SQL and a different number.
- Business definitions (what counts as revenue?) must live in the prompt or schema documentation, and the model does not always follow them.
- Row-level permissions, query cost and timeouts have to be enforced outside the model; the [checklist for securing database access](https://www.ruebstudio.de/en/guides/ai-agent-integrations/checklist-secure-database-access-ai-agents) covers each control.

Vendors who ship text-to-SQL features say as much. The [Snowflake Cortex Analyst documentation](https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-analyst) notes that generic AI solutions often struggle when given only a database schema, because schemas lack knowledge of business processes and metric handling.

## Fixed queries: strengths and weaknesses

Fixed queries are reviewed, parameterised SQL that the agent calls as a tool (see [tool use / function calling](https://www.ruebstudio.de/en/glossary/tool-use-function-calling)). The model only chooses the right query and fills in parameters such as a date range or customer number. This gives the lowest error risk and the narrowest coverage.

**Strengths:**

- Someone who knows the ERP schema reviewed the SQL once; the agent cannot alter it.
- Results are repeatable and can be reconciled with existing reports.
- Permissions and runtime limits can be set per query, for example via a dedicated database role or view.

**Weaknesses:**

- Anything outside the catalogue goes unanswered.
- As the catalogue grows, variants of the same metric appear and can drift apart.
- Every schema change has to be applied to each affected query.

Data platforms now offer this pattern natively. Databricks calls reviewed example queries and registered SQL functions [trusted assets](https://docs.databricks.com/aws/en/genie-agents/tune-quality); when a parameterised example query is used to build a response, Genie returns it as a verified answer.

## Semantic layer: strengths and weaknesses

A semantic layer defines metrics, dimensions and table relationships once, and generates SQL from those definitions. The agent asks for a metric grouped by dimensions rather than for tables and columns. Definitions stay consistent, and coverage is far wider than a query catalogue.

**Strengths:**

- One definition for every consumer. The [dbt documentation](https://docs.getdbt.com/docs/use-dbt-semantic-layer/dbt-sl) says centralising metric definitions means different business units work from the same definitions, whatever tool they use.
- Cryptic column names are translated once into meaningful names, so the model sees "net revenue" rather than an abbreviation.
- Agents can connect directly. According to the [Cube documentation](https://docs.cube.dev/docs/introduction), AI agents connect through an MCP server or chat API and query the semantic layer instead of the warehouse.

**Weaknesses:**

- Building it takes time, because finance, operations and IT have to agree on definitions.
- Questions that need data outside the model stay unanswered.
- One more system to run, version and secure.

Snowflake applies the same idea in Cortex Analyst: semantic views describe logical tables, dimensions, facts, metrics and relationships, and can include verified example questions with their SQL.

## Which approach for which scenario?

The choice depends less on technology than on two questions: how costly is a wrong number, and how open-ended are the questions? The scenarios below are typical for mid-sized companies and show which approach to start with in each case.

- **Inside sales checks order status and open quotes.** A few recurring, parameterised questions: fixed queries. This is a typical building block of a [sales agent](https://www.ruebstudio.de/en/ai-agents/sales).
- **Management wants revenue and contribution margin by region, product group and month.** Many combinations of the same metrics: a semantic layer.
- **Finance investigates an unexplained variance.** Open, exploratory questions reviewed by experts: free text-to-SQL with read-only access and visible SQL.
- **Field service asks for equipment history and spare-part usage.** Mostly fixed queries, with a semantic layer once analysis across many attributes is needed.

Free SQL is the wrong choice when answers flow unchecked into quotes, invoices or regulatory reports. A semantic layer is overkill when there are only a handful of questions.

## How to combine them: a tiered hybrid

A practical hybrid works in tiers: vetted queries first, then the semantic layer, and free SQL last as an explicitly labelled fallback. Each tier records where the answer came from. Users get reliable numbers where they exist and an honest label where they do not.

A four-step flow:

1. **Check the query catalogue.** If the question matches a vetted query, the agent calls it with parameters. The answer is marked as verified.
2. **Ask the semantic layer.** If the question can be expressed as metrics plus dimensions, the layer generates the SQL.
3. **Fall back to free SQL.** Read-only, with time and row limits, on approved views only. The answer shows the SQL and states that it has not been verified.
4. **Collect the gaps.** Every question that reaches step 3 is logged. Recurring ones become new vetted queries or metrics.

The verified share grows with use. It helps to review the step 4 log on a fixed schedule rather than waiting for complaints about wrong figures. Steps 2 and 3 both depend on good schema documentation: what each column means, which document types count and which filters always apply.

## Migrating from prototype to production

Many teams start with free text-to-SQL because a prototype is quick to build. The path to trustworthy numbers runs through a log of real questions. Those become vetted queries first and, where metrics repeat, a semantic layer, without throwing the prototype away.

A workable order:

- **Log questions:** store the question, generated SQL, result and user feedback.
- **Pin down the most frequent questions:** turn the top ten to twenty into vetted, parameterised queries and reconcile them with existing reports.
- **Consolidate metrics:** when the same metric appears in several queries, move it into a semantic layer.
- **Contain the fallback:** free SQL stays available but clearly labelled and limited to approved views.

If you are planning agents on top of ERP data and need to decide which questions require verified answers, the overview of [AI agents for mid-sized companies](https://www.ruebstudio.de/en/ai-agents) shows where they fit. The security foundations, including read-only roles, views and query limits, are covered in the pillar guide [Connecting an AI Agent to Databases](https://www.ruebstudio.de/en/guides/ai-agent-integrations/connect-ai-agent-to-database).

## Frequently asked questions

### How accurate is text-to-SQL today?

On the BIRD benchmark, the top overall score in October 2026 was 83.40% execution accuracy against a human baseline of 92.96%. On realistic enterprise tasks (Spider 2.0), the agent tested in the paper solved only 21.3% of tasks.

### Do I need a new data warehouse for a semantic layer?

No. Tools such as the dbt Semantic Layer or Cube sit on top of existing tables. The real work is agreeing on metric definitions once.

### Should an agent ever write to the database?

Not for analytics. Whichever approach you choose, give the agent a read-only role and expose curated views rather than raw ERP tables.

### How do I know which questions need a vetted query?

Log every question that falls through to free SQL. The ones that recur, or that feed decisions, are the candidates for vetted queries or semantic-layer metrics.

## Sources

- [Spider 2.0: Evaluating Language Models on Real-World Enterprise Text-to-SQL Workflows (arXiv)](https://arxiv.org/abs/2411.07763)
- [BIRD-SQL benchmark and leaderboard](https://bird-bench.github.io/)
- [Can LLM Already Serve as A Database Interface? A BIg Bench for Large-Scale Database Grounded Text-to-SQLs (arXiv)](https://arxiv.org/abs/2305.03111)
- [dbt Semantic Layer documentation](https://docs.getdbt.com/docs/use-dbt-semantic-layer/dbt-sl)
- [Snowflake Cortex Analyst documentation](https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-analyst)
- [Databricks Genie: improve quality with trusted assets](https://docs.databricks.com/aws/en/genie-agents/tune-quality)
- [Cube documentation: introduction](https://docs.cube.dev/docs/introduction)
