semlayer

Your AI writes perfect SQL and returns the wrong number.

semlayer is a command-line tool that reads your data warehouse and writes the semantic layer your AI agents need — what each table and column means, the foreign keys nobody declared, the filters your summary tables silently apply, and your metric definitions — as one open file, served to any agent over MCP. It infers all of it from your data. Nobody hand-writes a model, and nobody maintains it.

Your company pointed Claude or Copilot at the data warehouse, and your business users can finally ask their own questions. The answers come back in seconds, they look right, and more than half of them are wrong.

Nothing errors. Nothing warns anyone. The query is valid, it just answers a slightly different question than the one that was asked — because it does not know that cancelled orders never count as revenue, or which of your four order tables is the one finance uses.

That knowledge is real, and it is not written down anywhere a machine can read. It lives in the heads of the three engineers who built the warehouse.

What semlayer does

A nineteenth-century
  botanical plate: a passionflower drawn whole at the centre, with its leaves,
  buds, flower and sectioned fruit each drawn separately in bordered panels
  around it.

It works those rules out for itself, from your data. Point it at your warehouse and it reads every table, finds the relationships nobody declared, decodes what your status columns mean, and recovers the filters your summary tables silently apply. It writes all of it down in one open file that any AI agent can read.

That includes your metrics. “Average order value” is not a column anywhere. It is a decision somebody made about what to divide by, and the two defensible answers can be three times apart. Which is why two people pull the same metric, both do it correctly, and arrive at the same meeting with different numbers — nobody made a mistake, they used different definitions. semlayer writes the decision down: which rows count, what the denominator is, and the evidence behind it. Trust is not only about getting a correct number. It is about the same question returning the same number, to everyone, every time. How metrics are defined →

Same AI, same 38 business questions, same warehouse: 42% answered correctly from the raw schema, 87% with the context semlayer inferred. The errors it fixes are the silent kind — raw-schema “total revenue” sums cancelled orders, reporting $16.3M where finance reports $14.6M. Method, questions and both results →

Re-run it on a schedule and the context stays in step with the schema. Your engineers add what only they know on top, and that is never overwritten.

Where it does not help: on a clean, well-documented warehouse the raw schema already wins — 67% correct without semlayer, 58% with it. That result ships in the repo next to the good one. If your warehouse is tidy, you do not need this.

How it works

A
  close-up of a timber joint in walnut, where an upright post meets a horizontal
  rail and the end of the tenon passes through and stands proud of it.

It profiles every column, discovers the foreign keys nobody declared, decodes the status columns, recovers business rules hiding in your aggregate tables, and proposes the metrics those rules imply — verified against your own data, with confidence, provenance, and a review queue on every claim. Statistics alone never auto-accept a foreign key, and a doc that contradicts your data goes to review rather than being believed. What the confidence numbers mean →

pip install semlayer
semlayer init snowflake              # generates a minimal-grant, read-only setup script
semlayer infer snowflake -o layer.yaml --context ./docs/
semlayer review layer.yaml           # accept/reject what it inferred
semlayer mcp layer.yaml              # serve it to Claude, Cursor, any agent

The inference runs an LLM over your schema and statistics, not over your rows, and you bring your own key. A measured cost model and an MCP setup guide are in the docs.

Warehouses it reads

Snowflake, BigQuery, PostgreSQL and DuckDB, plus Iceberg on S3 through the DuckDB bridge. The PostgreSQL connector also reaches Redshift and other Postgres-protocol engines, though their catalogs differ in places and we have not tested them — if you try one, we would like to hear what broke.

It connects read-only. semlayer init generates the minimal-grant script for your warehouse, and the reader role is proved unable to write: on PostgreSQL by a test that runs in ordinary CI against a real server, and on Snowflake by a live suite you can run against your own account.

Exports to dbt, with any loss in translation reported rather than silent. Skip the quarter of hand-writing dbt YAML.

GitHub → Quickstart Watch the series

Resources

Start

Understand the problem

Check the claim

Reference