GitHub - MotleyAI/slayer: An embeddable, expressive semantic layer for AI agents and humans
SLayer is an open-source Python semantic layer that sits on top of a data warehouse so AI agents and people can query metrics without writing SQL by hand. You define a column like revenue once, then query it with expressions such as avg(revenue) or time_shift(sum(revenue), -1, 'year').
- Unlike traditional BI semantic layers, which need every metric and aggregation predefined, SLayer lets agents combine metrics, apply transforms like time shifts, and change aggregations on the fly.
- It handles read-only database connectivity, SQL generation, and row-level security, so the LLM doesn't have to write raw SQL.
- It exposes the same definitions over MCP, REST, CLI, Python, Flight SQL, and a Postgres-style SQL API, and imports configs from dbt, Cube, and Ossie.
- Install is via uv, and it can be added to Claude Code as an MCP server with a demo Jaffle Shop database for a quick start. It sends aggregated usage stats once a day unless you opt out.
SLayer is an open-source (MIT) semantic layer that sits between a data warehouse and AI agents, so an LLM can answer business questions without writing raw SQL against your tables. You define a column like `revenue` once, and then query it with expressions such as `sum(revenue)`, `avg(revenue)`, `sum(revenue) / count(*)`, or `time_shift(sum(revenue), -1, 'year')`. Multi-stage queries are supported too. The pitch is that traditional semantic layers in BI tools required every metric and aggregation to be predefined, which breaks down when an agent gets a question involving ratios, time shifts, or a different aggregation of the same field. SLayer handles read-only database connectivity, SQL translation, common transformations, and row-level security, and it's built around an agentic search, inspect, query loop with a search tool and a memory store for business context.
Access is flexible. You can run it standalone or import it as a Python library, and it exposes MCP, REST, CLI, Python, Flight SQL, and a Postgres-compatible SQL API, covering most popular databases. It also imports existing definitions from dbt, Cube, and Ossie configs, so it's meant to sit alongside a current stack rather than replace it. The README's demo runs a question, "show monthly revenue by store, with month-over-month % change," against the bundled Jaffle Shop database, showing the LLM-generated SQL next to the equivalent SLayer query. The article doesn't include the actual SQL output or any benchmark of accuracy, so the side-by-side comparison is something you'd have to check yourself in the docs.
Setup is short. Install with `uv tool install 'motley-slayer[all]'`, then either add the Jaffle Shop demo to Claude Code with `claude mcp add slayer_demo -- slayer mcp --demo` for a zero-config try, or point it at a real database with `slayer datasources create` using a connection string that reads the password from an environment variable. That password is read at init and not written to disk. One gotcha: the MCP subprocess inherits its environment from the shell that launches Claude Code, so `DB_PASSWORD` has to be exported there. On privacy, the `slayer` CLI sends anonymous, aggregated usage stats at most once a day (command counts, versions, and the like, never queries, names, data, or credentials). Library use sends nothing. You can turn it off with `SLAYER_USAGE_REPORTING=off`, `DO_NOT_TRACK=1`, or `slayer usage-reporting disable`. Worth saving if you're evaluating it for a team that handles sensitive warehouse data.