Nobody wants to import your library
Nobody wants to import your library
没人想导入你的库
I wrote a Python library. Then I watched people not use it. Not because they disagreed with it — the thesis landed fine. The problem was the shape of the ask. Nobody says “I’d like a Catalog object.” They say “my agent keeps showing the model tables this user isn’t allowed to read, and I already have an agent.” Between those two sentences sits an afternoon of wiring that nobody has budgeted. So most of the work on schemagate since the first release has gone into surfaces that require importing nothing. 我写了一个 Python 库,然后眼睁睁看着大家不去用它。不是因为他们不同意我的观点——核心理念本身没问题。问题在于“需求的形式”。没人会说“我想要一个 Catalog 对象”,他们会说“我的智能体总是把用户无权读取的表展示给模型,而且我已经有一个智能体了”。在这两句话之间,隐藏着一个没人愿意投入时间的下午去进行繁琐的配置。因此,自首次发布以来,schemagate 的大部分工作都集中在那些“无需导入任何代码”的使用界面上。
Here are five, in the order of how little you have to change to use them. 以下是五种使用方式,按你需要改动的代码量从少到多排序。
1. The command line, which now answers select used to print a table list.
1. 命令行,现在不仅能打印表列表,还能直接回答查询。
It felt like a demo of an idea rather than a thing that does work. 这感觉更像是一个概念演示,而不是一个真正能干活的工具。
pip install schemagate
schemagate demo "which customers owe us money" --answer --provider anthropic --model <model-id>
Nine objects instead of forty-two, and hr_compensation was never a candidate because this caller doesn’t hold payroll. Across the benchmark that ships with the library the average prompt is 631 tokens against 2,583 for the whole schema — a 75.6% cut.
从四十二个对象缩减到了九个,而且 hr_compensation 从未被选中,因为调用者没有“薪资”权限。在库自带的基准测试中,平均提示词长度为 631 个 token,而完整模式则需要 2,583 个 token——减少了 75.6%。
To point at your own, the sibling command takes a URL: schemagate select --url postgresql://localhost/app "which customers owe us money" --answer, same flags. Drop --provider and you get no model call at all: it prints a prompt for you to paste into whatever chat window you already pay for, and schemagate select --url ... --sql "SELECT ..." runs what comes back.
若要指向你自己的数据库,可以使用同级命令传入 URL:schemagate select --url postgresql://localhost/app "..." --answer,参数相同。去掉 --provider 后,它不会调用任何模型:它会打印出提示词,让你粘贴到你已经在付费使用的聊天窗口中,然后通过 schemagate select --url ... --sql "SELECT ..." 来运行返回的结果。
2. The Studio, for the thing you can’t read in a log
2. Studio,用于查看日志中无法读取的内容
A local page where you type a question, flip the caller’s roles, edit hints, and watch what reaches the prompt and what doesn’t. The value isn’t the UI, it’s the negative space: the panel that lists what was withheld from this caller, next to the DDL that was actually sent. 这是一个本地页面,你可以在其中输入问题、切换调用者角色、编辑提示词,并观察哪些内容进入了提示词,哪些没有。其价值不在于 UI,而在于“负空间”:面板会列出对该调用者屏蔽的内容,并与实际发送的 DDL 并排显示。
3. MCP, if your client speaks it
3. MCP,如果你的客户端支持它
The part I spent the most time on is that it doesn’t die. The index lives in memory after startup, so the database going away doesn’t take the server with it: select_schema keeps answering from the last good reflection and refresh_catalog reports the failure instead of raising. Every tool catches everything and returns {"error": ...}, because one bad request shouldn’t end the session for the other clients.
我花时间最多的地方在于确保它不会崩溃。索引在启动后驻留在内存中,因此数据库断开连接不会导致服务器宕机:select_schema 会继续根据最后一次有效的反射结果进行回答,而 refresh_catalog 会报告失败而不是抛出异常。每个工具都会捕获所有错误并返回 {"error": ...},因为一个错误的请求不应该导致其他客户端的会话中断。
4. LangChain, with identity bound at construction
4. LangChain,在构建时绑定身份
from schemagate.integrations.langchain import SchemagateRetriever, prompt_fragment
retriever = SchemagateRetriever(catalog=cat, top_k=6, principal=Principal("okta:jdoe", roles={"finance"}))
chain = retriever | RunnableLambda(prompt_fragment) | your_sql_prompt | llm
The principal goes in the constructor, not the call. Build one retriever per caller. A chain cannot forget to pass identity if the retriever already holds it, and “forgot to pass identity” is exactly the bug class this library exists to remove. 身份信息在构造函数中传入,而不是在调用时。为每个调用者构建一个检索器。如果检索器已经持有身份信息,链式调用就不可能忘记传递它,而“忘记传递身份”正是这个库旨在消除的 Bug 类型。
5. One click on Oracle Cloud
5. Oracle Cloud 一键部署
For a shared endpoint rather than a desktop: a Resource Manager stack that stands up an Always-Free-eligible VM running the MCP server against an Autonomous Database it creates, or one you already have. On first boot the instance principal calls OCI Generative AI to write a one-sentence description of every table and view. No API key is stored anywhere, and the prompts — schema metadata only, never… 针对共享端点而非桌面端:一个资源管理器堆栈,可以启动一个符合“永久免费”条件的虚拟机,运行针对自治数据库(Autonomous Database)的 MCP 服务器。首次启动时,实例主体会调用 OCI 生成式 AI,为每个表和视图编写一句描述。过程中不会存储任何 API 密钥,且提示词仅包含模式元数据,绝不会……