Teams have tried getting LLMs to write raw SQL since 2022, typically stuffing entire database schemas into prompts and hoping the model emits valid queries.

Production analytics workloads follow recurring query patterns. Exposing a fine-grained fact table beneath a Semantic Layer and letting the agent assemble semantic parameters proves far more reliable and flexible than raw text-to-SQL.

When a user asks, “Show me CPA and ROAS for high-spend keywords in a target ad group over the last 7 days,” the LLM never writes SQL directly. Instead, it parses the question into five semantic building blocks: Dimension, Metric, Filter, Order, and Comparison.

The LLM emits those structured components as arguments to a single Tool Call:

{
  "days": 7,
  "dimensions": ["keyword_id", "keyword_name"],
  "metrics": ["cost", "conversions", "cpa", "roas"],
  "filters": [
    {
      "field": "adgroup_name",
      "operator": "contains",
      "value": "target ad group"
    }
  ],
  "order_by": {
    "field": "cost",
    "direction": "desc"
  }
}

An internal Python tool or deterministic query builder then compiles those arguments into executable SQL and runs the query.

Pairing 100% Valid SQL Assembly with Agent Autonomy

SQL compiled through a Semantic Layer executes with 100% syntax accuracy. Rather than sidelining the LLM, this design shifts its job from guessing SQL dialect quirks to mapping user intent onto clean semantic dimensions and metrics.

Data Modeling Returns as a Core Engineering Asset

Data engineering discipline around fact modeling and pipeline governance becomes central again in the agent era. Instead of making data engineers obsolete, the semantic definitions curated by the Human Layer act as safety guardrails, putting years of data lakehouse modeling craft directly to work.

Even a single well-modeled Semantic Layer tool gives an analytics agent broad, accurate coverage. Handing an agent structured assembly blocks works far better than exposing raw table schemas.

Summary

  • Placing a Semantic Layer over granular fact tables beats dumping full DB schemas into an LLM for raw SQL generation.
  • Instead of writing SQL syntax, the LLM extracts Dimension, Metric, Filter, Order, and Comparison arguments into a structured Tool Call.
  • Deterministic query compilation from engineer-defined semantic models guarantees 100% syntax-error-free SQL execution.