{
 "schema_version": 1,
 "generated": "2026-10-24",
 "id": "ashishsinha1602-schemagate--gate-schema-in-a-langchain-or-mcp-agent",
 "repo": "ashishsinha1602/schemagate",
 "repo_url": "https://github.com/ashishsinha1602/schemagate",
 "repo_slug": "ashishsinha1602-schemagate",
 "title": "Gate the schema inside a SQL agent's Python code",
 "page_title": "How to gate the schema inside a SQL agent's Python code with Schemagate",
 "summary": "Load a catalog, restrict a table to one role, and pass only the selected schema fragment into your agent prompt.",
 "who": "A developer shipping a LangChain or MCP SQL agent who must make sure the system prompt never names tables the caller cannot read.",
 "problem": "Agent frameworks typically build the schema prompt before any access check, which leaks table names and structure to the model.",
 "outcome": "Your agent's system prompt contains only the selected DDL, and a restricted table's name does not appear anywhere in the prompt text.",
 "steps": [
  "Run `pip install schemagate` and install the driver extra for your database, such as `pip install 'schemagate[postgres]'`.",
  "In Python, create the catalog with `Catalog().bootstrap(\"postgresql://localhost/app\")` or load the bundled one with `demo_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 pass `sel.prompt_fragment()` into your system prompt. (inferred, check the README)"
 ],
 "agent_prompt": "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.",
 "agents": [
  "any"
 ],
 "difficulty": "Advanced",
 "time": "1 hour",
 "basis": "readme",
 "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.",
 "category": "Data and analytics",
 "tags": [
  "Data and analytics"
 ],
 "lang": "python",
 "requirements": [
  "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"
 ],
 "risk": "none",
 "seen_in_the_wild": false,
 "mentioned_publicly": false,
 "risks": [],
 "best": false,
 "score": 0.8,
 "evidence": [],
 "url": "https://dedupedai.com/use-cases/ashishsinha1602-schemagate/gate-schema-in-a-langchain-or-mcp-agent/",
 "md": "https://dedupedai.com/use-cases/ashishsinha1602-schemagate/gate-schema-in-a-langchain-or-mcp-agent/index.md",
 "disclaimer": "Deduped lists open-source repositories that belong to other people. We do not own, maintain, audit, or vouch for any of them, and a repo appearing here is not an endorsement or a safety check. The use cases, steps, and prompts are written by AI and may be incomplete, outdated, or just wrong. Where a use case is marked \"Seen in the wild\", we link to public posts where someone described something similar, but we have not verified those posts and the use case itself is still our AI's own write-up. Use all of this at your own risk. Only run code, commands, or agents on systems and accounts you are authorized to use, and read the code and every command before you run it, especially anything that touches credentials, files, or the network. Nothing here is professional, security, legal, or financial advice. All trademarks and project names belong to their respective owners, and their use here does not imply affiliation. Content is provided as is, without warranties of any kind. Found a mistake, a safety problem, or something you want removed? Email hello@dedupedai.com and we will look at it promptly.",
 "api": "https://dedupedai.com/api/v1/usecases/ashishsinha1602-schemagate--gate-schema-in-a-langchain-or-mcp-agent.json",
 "api_version": "v1"
}
