DEV Community

Mads Hansen
Mads Hansen

Posted on

Your AI SQL agent needs a semantic layer, not just table names

Table names are not business context.

An AI database agent can see orders, subscriptions, events, and users.

That does not mean it knows what revenue means, which timestamp counts, or which joins are approved.

Production natural-language SQL needs a semantic layer, not just schema introspection.

The schema is only the map of storage

Database schemas describe how data is stored.

Business questions ask what data means.

Those are different layers.

For example, “active customer” might exclude:

  • trials
  • internal accounts
  • refunded subscriptions
  • test tenants
  • suspended workspaces

A model cannot reliably infer that from table names.

A useful semantic layer should provide:

  • business metrics and formulas
  • approved entities and relationships
  • safe joins and join grain
  • default filters and exclusions
  • freshness expectations
  • owner and review metadata
  • examples of valid questions and result shapes

Longer version: Semantic layers for AI database agents

The practical rule:

If a metric would cause a Slack argument between humans, do not make the model guess it from schema names.

Top comments (0)