Future of AI
Why Text-to-SQL is Failing in Production (And Why the Future is LLMs Querying Semantic Layers)
Raw Text-to-SQL looks amazing in playground demos, but it breaks spectacularly on messy, real-world schemas. Here is why the industry is shifting to LLMs querying structured semantic layers instead.
Updated 11/15/2026
We have all seen the dazzling Text-to-SQL demos. You type a simple natural language question like, "Who are our top ten customers by margin in the UK?", and a shiny dashboard widget instantly populates. The LLM generates a flawless SELECT query, executes it against a pristine three-table mock database, and everyone in the room applauds.
Then you attempt to deploy this system into production.
You connect the LLM to your actual enterprise data warehouse—a labyrinthine archive built over nine years, containing tables with names like user_metadata_v2_final_backup and columns containing undocumented JSON blobs. Within minutes, the LLM hallucinates a join that doesn't exist, triggers an accidental Cartesian product, locks your database, and sends your database administrator’s Slack status into a fiery rage.
The dream of raw, zero-shot Text-to-SQL is dead on arrival for serious production systems. But the dream of natural language data access isn't. To make it work, AI builders are shifting their architectures away from raw schema generation and toward a much more stable intermediary: the semantic layer.
The Illusion of the Clean Schema
Text-to-SQL fails in the real world because it assumes your database is a logical, self-documenting masterpiece. In reality, production databases are geological digs. They are layered with legacy business logic, deprecated columns that are still half-populated, and inconsistent naming conventions.
An LLM attempting to write raw SQL has to solve two incredibly hard problems simultaneously: 1. The Translation Problem: Mapping the user's ambiguous intent (e.g., "active user") to concrete database rules. 2. The Syntax Problem: Remembering the exact syntax, dialetic nuances (Postgres vs. Snowflake vs. BigQuery), and join keys of your specific database.
If you ask a model to write SQL directly, you are forcing it to act as both a business analyst and a database administrator. While state-of-the-art models like /platforms/claude are astonishingly capable code generators, they cannot guess that your company calculates "net revenue" by subtracting column tax_rate_b from gross_amt only when status_flag is not 'D' or 'P'.
Without explicit, exhaustive documentation of every single table and business rule crammed into the system prompt—which quickly devours your context window and degrades retrieval accuracy—the LLM is left guessing. And when an LLM guesses, databases break.
Set up your AI once so you repeat yourself less.
Tickd is independent and not affiliated with any AI company.
Why Raw SQL is Too Fragile for Autonomous Agents
When we transition from human-in-the-loop chat interfaces to autonomous agents, the fragility of raw SQL becomes an existential threat to your application's reliability.
If an agent is running a loop to answer a complex analytics query, it needs a predictable interface. Raw SQL is anything but predictable. An LLM might generate a query that executes perfectly but returns semantically incorrect data because it used the wrong date column (e.g., created_at instead of activated_at). Because there was no database error, your agent happily presents incorrect financial data to a decision-maker.
Furthermore, giving an LLM direct SQL write access—even read-only access—presents massive security and performance risks. It is incredibly difficult to enforce row-level security or prevent an accidental, unindexed heavy query from exhausting your database resources when the agent is writing the raw execution code.
To build agents that can be trusted with business data, we need to abstract the database entirely. We need a clear translation directory—a /glossary of business terms—that sits between the AI and the raw storage.
Enter the Semantic Layer: The LLM's New Best Friend
Instead of pointing an LLM at a raw database schema, forward-thinking builders are pointing LLMs at a semantic layer (using tools like Cube, dbt Semantic Layer, or Looker's LookML).
A semantic layer is a middleware platform that sits between your data sources and your data consumers. It defines your data models, metrics, and relationships in clean, declarative configuration files (usually YAML or JSON). It abstracts the underlying SQL complexity away.
In this new paradigm, the workflow shifts dramatically:
- The User Asks a Question: "What was our average order value last week?"
- The LLM Queries the Semantic Layer: Instead of writing a complex SQL query with multiple joins and date truncations, the LLM generates a simple, structured API call (or a JSON payload) to the semantic layer. It asks for the metric
average_order_valuegrouped by the dimensionorder_date.weekwhere the filter islast week. - The Semantic Layer Generates the SQL: The semantic engine—which has a deterministic, mathematically sound understanding of your data relationships—takes this clean request and compiles it into highly optimised, safe SQL tailored specifically to your target database.
- The Database Returns the Result: The data is fetched safely, securely, and with 100% accurate business logic.
By using a semantic layer, you completely eliminate the syntax problem for the LLM. The LLM only needs to understand the high-level business concepts, while the deterministic compiler handles the dirty work of translating those concepts into raw, high-performance database queries.
Why This Architecture Wins
This architectural shift solves almost every major pain point of building natural language data tools:
- Deterministic Accuracy: Business metrics like "Active Users" or "Churn Rate" are defined exactly once in the semantic layer. The LLM cannot hallucinate its own creative definition of these terms because it doesn't write the underlying SQL code.
- Perfect Security: You can enforce access controls, row-level security, and data masking directly within the semantic layer. The LLM never has the opportunity to bypass these rules because it cannot alter the generated SQL.
- Substantially Lower Token Consumption: You no longer need to feed thousands of lines of raw database DDL into the LLM's prompt. You only need to provide a lightweight list of the semantic layer’s available metrics and dimensions.
- Database Agnostic: If you migrate your data warehouse from Snowflake to BigQuery, your LLM application remains completely untouched. The semantic layer handles the dialect translation under the hood.
How to Start Architecting for the Semantic Future
If you want to build data-fluent agents that don't fall over, stop trying to write the perfect system prompt to teach your model how to parse your legacy Oracle database.
Instead, spend that engineering effort defining a clean, machine-readable API for your data. Use declarative configuration files to map out what makes your data warehouse tick. Turn your messy database into an organised, searchable directory of business metrics, and let your LLM query that directory instead.
By decoupling business logic from raw data execution, you turn one of the most notoriously fragile LLM use cases into a robust, deterministic feature that is actually ready for production.
Keep going
Build something with the prompt generator, decode the jargon in the glossary, or compare the tools on our platform deep-dives.