Who it is forA developer shipping a LangChain or MCP SQL agent who must make sure the system prompt never names tables the caller cannot read.
The problemAgent frameworks typically build the schema prompt before any access check, which leaks table names and structure to the model.
The outcomeYour agent's system prompt contains only the selected DDL, and a restricted table's name does not appear anywhere in the prompt text.
What you need first
- Python and pip installed
- For your own database: a reachable Postgres, Oracle, MySQL or SQL Server URL, and the matching schemagate extra
- Optional: a model key only if you want generated answers or AI descriptions
Steps
- Run
pip install schemagateand install the driver extra for your database, such aspip install 'schemagate[postgres]'. - In Python, create the catalog with
Catalog().bootstrap("postgresql://localhost/app")or load the bundled one withdemo_catalog(). - Call
cat.restrict("hr_compensation", ["payroll"])to limit that table to the payroll role. - Call
cat.select("revenue by month", top_k=6, principal=Principal("okta:jdoe", roles={"finance"}))and passsel.prompt_fragment()into your system prompt. (inferred, check the README)
Prompt for your agent
Using the schemagate Python API, bootstrap a Catalog from <database-url>, restrict the table <restricted-table> to the role <role>, and select tables for the question <question> for a Principal with that role. Return sel.prompt_fragment() and confirm the restricted table name does not appear in it.
Caveat. The README's example uses Catalog and Principal calls that you must verify against the installed version, since the library's documented API is what this depends on.
Use this in your AI agent
Ask your agent
Using the Deduped MCP, get the setup steps for ashishsinha1602/schemagate and "Gate the schema inside a SQL agent's Python code"
Add Deduped to Claude Code once
claude mcp add --transport http deduped https://dedupedai.com/mcp
Every Monday: the 5 hottest repos and exactly how to use them. Free, one email a week, unsubscribe anytime.
Get them freeShare: X LinkedIn Hacker News Email Copy link
Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer