schemagate is an open-source tool for Text-to-SQL scenarios with two core goals: reducing the number of database schema tokens sent to large language models, and filtering tables by caller identity before the model sees the schema.
Purpose Most Text-to-SQL systems paste the entire database schema into the prompt for every question, which is costly when there are many tables. A more serious problem is that schema selection happens before query execution and before row-level security (RLS) takes effect. If the selection step is not aware of caller identity, the model may receive tables the caller has no permission to read and generate valid SQL, but RLS will filter out all rows, and the user will see "no records" without being able to distinguish whether the data does not exist or access is unauthorized. schemagate solves this problem by filtering tables according to caller authorization before the model sees the schema.
Main capabilities
- Filter tables first by caller authorization: tables the caller has no permission to read do not appear in the prompt, rather than being ranked later.
- Schema selection: send only the tables needed to answer the question. The material states that on databases with more than 50 tables, the median schema token reduction is 91.1%; on real BigQuery and Snowflake warehouses in Spider 2.0, the median reduction for databases with more than 50 tables is 91.1%.
- Retrieval method: uses reciprocal rank fusion of BM25 and vector similarity, and pulls in join tables not mentioned in the question along foreign key relationships.
- Supports multiple databases: Postgres, Oracle, MySQL, SQL Server, SQLite.
- Integration: can be used with LangChain, LlamaIndex, MCP, or any SQL agent.
- Local operation: the default embedder is an offline hashed n-gram vectorizer, requiring no API key and no model download, with consistent results across machines.
- Optional features: Hints, Glossary, local models (the huggingface extra dependency is relatively heavy), reranking, etc.
- Provides a browser demo and a hosted version at schemagate.app.
Usage The material provides installation and run commands, but the specific command contents are not fully given in the original material. It is known that it can be installed via PyPI, with drivers provided as extras, such as schemagate[postgres], [oracle], [mysql], [mssql], or schemagate[all]. The command line includes subcommands such as demo, select, and studio. select can point to a real database; studio opens a local page where you can enter questions, switch the caller role, edit prompts, and view what enters the prompt. It can also be run without installation using a container image that includes all drivers. The hosted version can connect to PostgreSQL, MySQL, SQL Server, Oracle, or spreadsheets, invite teams, and each person can only see the data they are authorized to view.
Use cases
- Text-to-SQL applications on large databases that need to control prompt costs.
- Multi-role, multi-permission database question-answering systems that need to prevent the model from touching unauthorized tables.
- Teams using LangChain, LlamaIndex, MCP, or self-built SQL agents.
- Scenarios that require local offline mode selection.
Limitations
- Schema selection may miss necessary tables. The material states that in the repository scenario, 86.7% of every table read by the gold-standard queries was selected.
- Savings are limited on databases with fewer tables; the BIRD median saving is 8.8%.
- The join graph is not enabled by default because it loses recall on business-language questions.
- The local huggingface model additionally requires about 2 GB of wheels plus a 3.1 GB model download, and is not included in schemagate[all].
- Hosted version pricing information: the material mentions a free 7-day trial, no credit card required, and an AppSumo lifetime deal, but specific prices are not provided.
- Some benchmark results are self-scored or pending confirmation, as noted in the material.