Skip to main content

langchain-schemagate

A LangChain retriever for text-to-SQL. Each question gets only the tables it needs, picked from the tables the caller may read. A table the caller can't read is never a candidate, so it can't reach the prompt.

pip install langchain-schemagate
from schemagate import Catalog, Principal
from langchain_schemagate import SchemagateRetriever, prompt_fragment

cat = Catalog().bootstrap("postgresql://localhost/app")
retriever = SchemagateRetriever(catalog=cat, top_k=6,
                                principal=Principal("okta:jdoe", roles={"finance"}))

docs = retriever.invoke("revenue by month")      # one Document of DDL per selected table
schema_for_prompt = prompt_fragment(docs)

It is a BaseRetriever, so it composes: retriever | RunnableLambda(prompt_fragment) | prompt | llm. Selection runs offline (BM25 plus a small embedder) and calls no model.

On Spider 2.0's public BigQuery and Snowflake schemas, the median database with 50+ tables went from the full schema to a selection 92.9% smaller, in prompt tokens. On small databases there is little to cut: 8.8% on BIRD's seven-table ones. The script and the recall trade-off are in schemagate's BENCHMARKS.md.

The retriever itself is maintained in schemagate, which also has the full guide: docs/langchain.md. This package is the langchain-<name> distribution LangChain lists integrations under, and it runs LangChain's standard retriever tests.

Apache-2.0.

Metadata

Release files for langchain-schemagate 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-schemagate 0.1.0
File Size Uploaded Provenance
langchain_schemagate-0.1.0.tar.gz 7.1 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-schemagate 0.1.0
File Interpreter ABI Platform
langchain_schemagate-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / langchain_schemagate-0.1.0.tar.gz

Download URL langchain_schemagate-0.1.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
64e4b4f7df0e2bd6d768d06bf66cf207fd02df98632ffd5665e5b30f8a0fc4cf
BLAKE2b-256 checksum
How to use checksums
002af9cb72b2cd0b26e8445dea79b2515e23e4b1903061c658d6d5aa92e903d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Release files / langchain_schemagate-0.1.0-py3-none-any.whl

Download URL langchain_schemagate-0.1.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5caa6f8b30271a388fcad7f289de23fb04e11c7fb8958d1795015ae1158c2019
BLAKE2b-256 checksum
How to use checksums
971688a63d52fbe16ecb078cffff078ba952d54936c7cb1c69dd3a8ff9d9a437
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Security for langchain-schemagate 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for langchain_schemagate-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page