Schema introspection and resolution toolkit for SQL agents
Project description
schemadex
Schema introspection and resolution toolkit for SQL agents.
schemadex is a Rust core with Python bindings that turns a live database into something an LLM agent can actually consume: a token-budgeted, sample-aware, fuzzy-resolvable view of every table and column, cached on disk so the agent doesn't re-pay the introspection cost on every turn.
Install
pip install schemadex # core + all backends
pip install "schemadex[langchain,langgraph]" # with framework adapters
Rust:
schemadex-core = { version = "0.1", features = ["postgres", "sqlite", "duckdb_backend"] }
10-line example
from schemadex import SchemaCache
cache = SchemaCache.from_url("postgres://localhost/mydb")
for name in cache.list_tables():
print(name)
result = cache.resolve("public.orders", "customer_idd")
print(result.matched, result.confidence) # 'customer_id', 0.98
prompt, tokens = cache.describe_for_agent(max_tokens=1500, hint="orders by region")
Why
LLM SQL agents fail in the same three ways over and over:
- They hallucinate column names because they got the schema in a thousand-token blob and forgot half of it.
- They retry the same broken query because they don't know
'No Delay'is the sentinel value covering 80% ofdelay_code. - They re-introspect on every step because there's nowhere obvious to cache the schema.
schemadex fixes all three:
- Resolution:
resolve_column(table, candidate)returns a confidence + alternatives instead of letting the agent guess. - Sampling:
sample_values=Truecollects top-K, percentiles, and flags any value over 40% frequency as a sentinel. - Cache: introspect once, persist to
~/.cache/schemadex/<db>/, refresh on DDL change. On a local 50-table SQLite, warm reads are ~47× cold (cargo bench --bench cache_refresh); on remote Postgres the ratio grows since cold is network-bound.
Backends
| Backend | Feature flag | Status |
|---|---|---|
| Postgres | postgres |
✅ |
| SQLite | sqlite |
✅ |
| DuckDB | duckdb_backend |
✅ (PK/FK omitted) |
| MySQL | — | planned (M8+) |
| BigQuery | — | planned (M8+) |
| Snowflake | — | planned (M8+) |
Layout
schemadex/
├── crates/
│ ├── schemadex-core/ pure-Rust introspection + cache + resolve
│ └── schemadex-py/ PyO3 bindings (built as `schemadex._native`)
├── python/schemadex/ pure-Python public surface
├── examples/ langchain, langgraph, quickstart
├── benches/agent-success/ benchmark harness (see docs/benchmark.md)
└── docs/ architecture + benchmark methodology
Project status
Pre-1.0. API is still in motion. See road_map.md for milestone tracking.
License
Licensed under either of MIT or Apache-2.0 at your option.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file schemadex-0.1.1.tar.gz.
File metadata
- Download URL: schemadex-0.1.1.tar.gz
- Upload date:
- Size: 47.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b2bf993aa425f575628b9a4bfe2fc5467ca90ffc98dd7869bad941a3b34aa2b
|
|
| MD5 |
5bc5c6c320e91ddc3b2b4e3990f91bc2
|
|
| BLAKE2b-256 |
1660821a9f55504df25b528352d0c92bc620eaaf960be473d9c44e55b3a1a633
|
File details
Details for the file schemadex-0.1.1-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: schemadex-0.1.1-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 14.3 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bdba12fdab561c2e854e59040c2f7356883ea742df77a828ce1735553444591
|
|
| MD5 |
9c0d8bb81e8bf72271b85b157e320765
|
|
| BLAKE2b-256 |
60b99e9cf1286ee50cdcd976fe6b9c7e667fbb3635e1e9b1d7437497e5e4944b
|
File details
Details for the file schemadex-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: schemadex-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 27.1 MB
- Tags: CPython 3.9+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29915bd080d9fec0d2771379c6349c8402d08e12682c016f9cf5afae3504b87c
|
|
| MD5 |
3f2c594cc4c18d18212edcea387cadd8
|
|
| BLAKE2b-256 |
524bb22da880df463da4f45a60a34a56502f11dbe3930646408f8afba57db499
|
File details
Details for the file schemadex-0.1.1-cp39-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: schemadex-0.1.1-cp39-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 20.6 MB
- Tags: CPython 3.9+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0927685239282db30f3dd110864f4618be4cf2ce9796ed5f3194d6e7fe841733
|
|
| MD5 |
ad7cf97c75e8082568095879066b38e0
|
|
| BLAKE2b-256 |
0f1c770fed7a244f41276be1c3f6b775dfb41000cdd25de1c876192b903d3820
|
File details
Details for the file schemadex-0.1.1-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: schemadex-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 16.4 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6736b2f1b29ec3214daaad363cfe9c9fbb108f416c00a1fed33e8f1e83c0bdbd
|
|
| MD5 |
bf26a523f0b38fe57886af784e356975
|
|
| BLAKE2b-256 |
de843dccd6f5754d82ffb20642deb76e885ab4ffc548a5906aaaa1dd9f7f265b
|
File details
Details for the file schemadex-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: schemadex-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 17.8 MB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e4b4b4435c9ab19a5769b113e34c28ab533cd66f2ff352c8ed4b605bc2cfeb7
|
|
| MD5 |
162f37f3a44d767740b53624b1160593
|
|
| BLAKE2b-256 |
b69234df8495ff4c4376d23a5d93f5256e9a6e30a7333e5195fe0cfb8144beb5
|