Skip to content

SchemaGuru

Schema intelligence for AI agents on data warehouses. SchemaGuru crawls a warehouse's catalog, measures what really joins and which values really occur, refuses join paths that multiply rows, lets people correct it in reviewable YAML, and hands an agent a question-scoped, token-budgeted view of all of it — as prompt text, tool calls, an MCP server or framework adapters.

import schemaguru as sg
guru = sg.Guru.connect("duckdb:///warehouse.duckdb")
print(guru.context("monthly revenue by customer segment"))

Status: alpha (0.1.0)

Measurement runs through FactLang (0.1.4 or later, installed with SchemaGuru). Every output on this site was produced by the real library on the test shop warehouse; the measured numbers in the generated pages come from the test suite's backend, which computes them with plain SQL on that warehouse, so the pages are reproducible byte for byte. The cloud warehouse readers (BigQuery, Snowflake, Redshift, Databricks, Oracle) are tested against recorded metadata, not yet validated live.

The problem: a wrong guess does not error

An agent that writes SQL against a warehouse knows what the names tell it. Names mislead in at least three common ways, and each returns a plausible, wrong number instead of an error. These three come from the shop warehouse SchemaGuru is tested on; the row counts are counted with plain SQL on that warehouse.

1. The wrong join

An agent asked for events per order joins orders → accounts → events on account_id. Both joins are "correct" (match rate 100%), yet the result has 3,335,000 rows for 10,000 orders — 333.5× — because both tables attribute many rows to one account. No error, a plausible number.

SchemaGuru measured both joins, saw accounts receiving two attribution edges, and refuses the route (find_join_path / schemaguru path shop.orders shop.events):

every route shop.orders -> shop.events pivots through hub shop.accounts on two attribution edges (fan-in > 10): a cartesian hazard

A safe route is returned with its keys and its weakest support:

  shop.payments → shop.orders → shop.customers · support 98.04%
    payments.order_id = orders.order_id (1:1)
    orders.customer_id = customers.customer_id (N:1)

2. The soft-delete flag that is never FALSE

orders.deleted is TRUE or NULL — never FALSE. The filter an agent writes from the name, WHERE NOT deleted, returns 0 rows; the live rows are 9,700. The measured values sit next to the human's soft-delete rule:

  live rows: (deleted IS NULL OR NOT deleted) (human, unchecked)
    deleted      BOOLEAN  values: TRUE (300) (measured 2026-11-24); null 97% (measured 2026-11-24); distinct 1 (measured 2026-11-24)

3. The enum that drifted in case

WHERE status = 'paid' counts 5,000 orders; 5,412 are paid. The overlay declares paid, refunded, cancelled; measurement found PAID as well. SchemaGuru keeps the human expectation and states the contradiction (here under a waiver with an expiry date):

  ⚠ WAIVED until 2027-01-31 (legacy upper-case rows being migrated): status: declared values 'paid','refunded','cancelled' — observed also 'PAID' (412 rows)
  ⚠ status: case drift: 'paid'/'PAID' differ only in case — compare case-insensitively
    status       VARCHAR  values: 'paid','refunded','cancelled' (+ observed 'PAID'); distinct 4 (measured 2026-11-24); Payment state of the order.

How SchemaGuru catches them

Trap What SchemaGuru does Read more
Row-multiplying join measures every candidate join in both directions (match rate, reverse coverage, fan-in); refuses a route that arrives at a hub on one many-to-one edge and leaves on another (HUB_PIVOT) Join graph
TRUE/NULL flag measures observed values and the null rate; shows the human's live-rows predicate next to them Measure
Case drift keeps a declared enum as an expectation, never rewrites it; reports what measurement saw beyond it Overlays
Narrow join a thin but correct join is returned labelled with its coverage; only broken joins are refused Join graph
Stale knowledge refresh re-measures, diffs against the previous snapshot and classifies each change Refresh

Every statement carries its provenance — catalog, declared, measured, drafted (by an LLM) or human — and every measured number carries its method and date. Unknown is shown as unknown, never as 0 or 100%. A view that shows a warning also says that the absence of a warning is not verification.

Before and after

What an agent often gets is the schema pasted into the prompt: every table, names and types, nothing about what joins.

CREATE TABLE shop.accounts (
  account_id INTEGER,
  name VARCHAR
);
CREATE TABLE shop.all_null_t (
  id INTEGER,
  c INTEGER
);
CREATE TABLE shop.anon_enum_t (
  id INTEGER,
  kind VARCHAR
);
CREATE TABLE shop.broken_child (
  child_id INTEGER,
  parent_id INTEGER
);
CREATE TABLE shop.customers (
  customer_id INTEGER,
  email VARCHAR,
  phone VARCHAR,
  segment VARCHAR
);
CREATE TABLE shop.empty_t (
  id INTEGER,
  v VARCHAR
);
CREATE TABLE shop.events (
  event_id INTEGER,
  session_id VARCHAR,
  account_id INTEGER,
  kind VARCHAR
);
CREATE TABLE shop.order_items (
  order_id INTEGER,
  line_no INTEGER,
  product_id INTEGER
);
CREATE TABLE shop.orders (
  order_id INTEGER,
  customer_id INTEGER,
  account_id INTEGER,
  status VARCHAR,
  created_at VARCHAR,
  deleted BOOLEAN
);
CREATE TABLE shop.payments (
  payment_id INTEGER,
  order_id INTEGER,
  amount INTEGER
);
CREATE TABLE shop.products (
  product_id INTEGER,
  name VARCHAR
);
CREATE TABLE shop.ref_child (
  child_id INTEGER,
  parent_id INTEGER
);
CREATE TABLE shop.ref_parent (
  id INTEGER
);
CREATE TABLE shop.sessions (
  session_id VARCHAR,
  started_at VARCHAR
);

What it gets from guru.context("monthly revenue by customer segment") once the shop is measured and its overlay loaded: the tables the question needs, with what was measured.

Legend:
  ⚠ a hazard: measured, declared by a person, or drafted (then marked (draft)).
  ≈ / ≥ estimated from a sample of a large table; never verified.
  (draft) written by a language model and not checked.
  measured <date> an observed number; verified <date> a claim that passed its check.
  (human, unchecked) / (declared, unchecked) stated by a person or a declaration; not yet checked against the data.
  Absence of a warning is not verification.

Glossary:
  active customer: ordered in the last 90 days [tables: shop.orders, shop.customers]

[shop.customers]
  1,000 rows (measured 2026-11-24)
  Columns:
    customer_id  INTEGER  PK (unique, measured 2026-11-24); ← shop.orders.customer_id (coverage 100%, measured 2026-11-24); distinct 1,000 (measured 2026-11-24)
    email        VARCHAR  distinct 1,000 (measured 2026-11-24)
    phone        VARCHAR  null 10% (measured 2026-11-24); distinct 900 (measured 2026-11-24)
    segment      VARCHAR  values: 'retail' (334), 'vip' (333), 'wholesale' (333) (measured 2026-11-24); distinct 3 (measured 2026-11-24)
  Provenance: measured 2026-11-24

[shop.orders] One row per order placed on the storefront.
  ⚠ Pitfall: Refunds are a second row with negative amount. — fix: Filter amount > 0 for gross revenue.
  ⚠ WAIVED until 2027-01-31 (legacy upper-case rows being migrated): status: declared values 'paid','refunded','cancelled' — observed also 'PAID' (412 rows)
  ⚠ status: case drift: 'paid'/'PAID' differ only in case — compare case-insensitively
  ⚠ created_at: stored as VARCHAR, holds ISO-8601 date text (100% of values, measured 2026-11-24) — CAST before comparing
  Answers: revenue by month; average basket size
  10,000 rows (measured 2026-11-24)
  live rows: (deleted IS NULL OR NOT deleted) (human, unchecked)
  Columns:
    order_id     INTEGER  PK (unique, measured 2026-11-24); ← shop.order_items.order_id (coverage 100%, measured 2026-11-24), ← shop.payments.order_id (coverage 5%, measured 2026-11-24); distinct 10,000 (measured 2026-11-24)
    customer_id  INTEGER  → shop.customers.customer_id N:1, match 98.04% (measured 2026-11-24); distinct 1,020 (measured 2026-11-24)
    account_id   INTEGER  → shop.accounts.account_id N:1, match 100%, coverage 40% (measured 2026-11-24); distinct 40 (measured 2026-11-24)
    status       VARCHAR  values: 'paid','refunded','cancelled' (+ observed 'PAID'); distinct 4 (measured 2026-11-24); Payment state of the order.
    created_at   VARCHAR  text holding ISO-8601 date text (see warning); note: ISO-8601 timestamp stored as STRING (human, unchecked); distinct 10,000 (measured 2026-11-24)
    deleted      BOOLEAN  values: TRUE (300) (measured 2026-11-24); null 97% (measured 2026-11-24); distinct 1 (measured 2026-11-24)
  Provenance: human overlay · measured 2026-11-24

Join paths (join keys, advisory; support = the weakest hop's match or coverage):
  shop.customers → shop.orders · support 100%
    orders.customer_id = customers.customer_id (N:1)

Not shown: no other candidate tables.

Try more questions, the join-graph explorer and this comparison in the demo.

Where it shines

Agents on huge warehouses. Metadata-only, paged, resumable crawls; search runs in the store's full-text index, so a view is scoped without loading every table. Lazy, budgeted measurement: an agent's question never spends warehouse money by itself.

Onboarding analysts. schemaguru context "<question>" prints what a newcomer needs: which tables answer it, which joins are measured, which columns hold traps.

Data-contract CI. Declare enums, joins and soft-delete rules in YAML; schemaguru refresh exits 1 when a change needs review, and view fingerprints detect prompt drift.

Migration audits. Measure the same joins before and after a move; the refresh report says which verdicts changed, judged relative to the previous snapshot.

Measured on the developer's machine (hardware-dependent): lexical table search over a synthetic 500,000-table store had a p95 of about 167 ms (tests/benchmark/, a worst-case vocabulary where one word matches a third of all tables); graph expansion over 50,000 joins took a median of about 0.48 s (benchmarks/bench_expand.py).

Install

pip install schemaguru            # core: FactLang + PyYAML
pip install 'schemaguru[duckdb]'  # plus a warehouse driver (one extra per warehouse)
Extra Adds Extra Adds
bigquery google-cloud-bigquery anthropic Anthropic drafting provider
snowflake snowflake-connector-python openai OpenAI-compatible drafting provider
redshift redshift-connector mcp schemaguru mcp (MCP SDK ≥ 2.3)
databricks databricks-sql-connector server HTTP server (Starlette, uvicorn)
postgres psycopg 3 langchain LangChain tools and retriever
duckdb duckdb llamaindex LlamaIndex tools
clickhouse clickhouse-connect openai-agents OpenAI Agents SDK tools
mssql pyodbc (SQL Server, Synapse) embeddings numpy (embedding retriever)
oracle oracledb tiktoken tiktoken token counter
trino trino postgres-store Postgres knowledge store
mysql PyMySQL (MySQL, MariaDB) all everything above

The readers for PostgreSQL, MySQL, ClickHouse, SQL Server, Trino and DuckDB are tested against real engines in CI. The BigQuery, Snowflake, Redshift, Databricks and Oracle readers are built from the documented system views and tested on recorded metadata, but not yet validated against live accounts.

Next: Getting started · Concepts · Demo