schemagate — fewer tokens for text-to-SQL, and only the tables the caller may read

Most text-to-SQL prompts carry the whole schema, and on a big database that is most of the prompt, on every question. schemagate sends the model only the tables the question needs: 91.1% fewer schema tokens (median) on databases with 50+ tables (benchmark). It filters by the caller's grants first, so restricted tables are absent from the prompt rather than ranked low. Works with LangChain, LlamaIndex, MCP, or any SQL agent, on Postgres, Oracle, MySQL, SQL Server and SQLite.
Don't want to run it yourself? schemagate.app is the hosted version. Connect PostgreSQL, MySQL, SQL Server, Oracle or a spreadsheet, invite your team, and everyone asks questions in plain English, each person seeing only the data they're allowed to. Free 7-day trial, no card needed, or pay once with the lifetime deal on AppSumo.


Measured, not drawn: python docs/media/make_token_gif.py rebuilds it from the seeded 1,201-object fixture, counting with tiktoken's cl100k_base.
On BIRD's leaderboard: 74.34 execution accuracy on the hidden test set, scored by the BIRD team (leaderboard). On BIRD Mini-Dev it scored SQLite 81.0, PostgreSQL 72.6, MySQL 72.4 with Claude Opus 5.5 and one model call per question, #1 in all three on that board; BIRD has since released an updated Mini-Dev (2026-10-28) and lists those results in its legacy table (run files).
If it cut your prompt, a ⭐ helps other people building SQL agents find it.

With row-level security alone the failure is quiet: the model writes valid SQL against a table the caller cannot read, RLS strips every row, and the user is told "no records found" — indistinguishable from "this data does not exist."