Skip to main content

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:

  1. They hallucinate column names because they got the schema in a thousand-token blob and forgot half of it.
  2. They retry the same broken query because they don't know 'No Delay' is the sentinel value covering 80% of delay_code.
  3. 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=True collects 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

schemadex-0.1.0-cp39-abi3-win_amd64.whl (14.3 MB view details)

Uploaded CPython 3.9+Windows x86-64

schemadex-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl (27.1 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

schemadex-0.1.0-cp39-abi3-manylinux_2_28_x86_64.whl (20.6 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ x86-64

schemadex-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl (17.8 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file schemadex-0.1.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: schemadex-0.1.0-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

Hashes for schemadex-0.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 62abe452258a4591a596b5b44238eae0eff9a436d845e4547356cfdbb07beb40
MD5 13e433079e706e25d62ee9563a0d0b98
BLAKE2b-256 74b5d394d9535e86658b7d01476894ab7f99323c7b73e172c24e1aaaa3881b15

See more details on using hashes here.

File details

Details for the file schemadex-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: schemadex-0.1.0-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

Hashes for schemadex-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d31b7fc1c34a580f2e4e70e2bbd1d618b228429e2f7e65fc0ab7a50995e8c4c0
MD5 b67baf3cf291ab5ab75f2f271e931cce
BLAKE2b-256 3267d5d01db317b5b2a3d836c29dcb326d8e631d8a85062463f42531d57b6991

See more details on using hashes here.

File details

Details for the file schemadex-0.1.0-cp39-abi3-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: schemadex-0.1.0-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

Hashes for schemadex-0.1.0-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 303a562885b6be3ada5671f892720fb019d13f5c0c913a293a6b06f763347cbe
MD5 f30e9badd26cf838865409dac78bec35
BLAKE2b-256 2627dac0d02ac5bc5824e27dcd751c6f2bb4a004249c848805ae8fd77dc31b3c

See more details on using hashes here.

File details

Details for the file schemadex-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: schemadex-0.1.0-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

Hashes for schemadex-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 009ab21ad5a5626b35982b670fff37b31d8d9213f925944dc9105846f1f5b70f
MD5 78c224e03d5a55a936f2ba806cf3dd57
BLAKE2b-256 c5188deac1adc8c0c9ec9c136c04239ddc98c320e04bbca176b3a4d42df04350

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page