Getting started¶
This page walks the shop warehouse from nothing to an agent-ready view. Every Python block
on it runs as written (the docs test executes them), in a directory holding the shop
warehouse as warehouse.duckdb and the example overlay as schemaguru.yaml; both are in
the repository's examples/ folder (python examples/duckdb_quickstart.py builds the
warehouse).
Install¶
SchemaGuru needs Python 3.10+. Its only required dependencies are FactLang and PyYAML; every
warehouse driver, LLM provider and agent framework is an optional extra (see the
install matrix). FactLang (factlang>=0.1.4,<0.2) is installed from PyPI
with it.
schemaguru doctor checks the installation. When the installed FactLang lacks a capability
SchemaGuru uses (measurement, cost estimates, sampling, composite joins, metadata SQL), its
factlang row is a WARN naming the missing ones; WARN rows do not fail the command (exit 0),
only a FAIL does (exit 3).
Connect¶
Guru.connect opens the URL through FactLang's connect() when it is installed, and
otherwise opens duckdb:// URLs with the DuckDB driver itself (read-only: SchemaGuru never
writes to a warehouse, and a mistyped path does not create a file). Other warehouses open
through FactLang's connect() (installed with SchemaGuru) and the warehouse's driver extra.
- The store. Knowledge lives in one SQLite file, by default
./.schemaguru/<name>.db(name="default"). Passstore=to put it elsewhere. - First use crawls. When the store holds no table yet,
connectcrawls the catalog — metadata only (table and column names, types, keys, comments, catalog statistics). Where the warehouse bills metadata queries and the reader reports the bytes (BigQuery), they are admitted againstBudget.crawl_bytes(default: no cap): at the cap the crawl stops withSG110and the next crawl resumes. Readers that report no bytes are not counted.crawl=Falseskips it;crawl=Truealways crawls. - Paths.
duckdb:///warehouse.duckdbis relative to the working directory; an absolute POSIX path takes four slashes,duckdb:////data/warehouse.duckdb. - DuckDB file names. DuckDB names a database's catalog after its file, so a file
shop.duckdbholding a schemashopmakesshop.ordersambiguous to DuckDB itself. Name the file differently from its schemas.
Ask a question¶
view = guru.context("monthly revenue by customer segment")
print(view.text)
print(view.tokens, "tokens;", [t.canonical() for t in view.tables])
Before anything is measured, the view holds catalog knowledge and says so:
[shop.customers]
unmeasured: nothing here has been measured yet; figures are declared or drafted
1,000 rows (catalog stats)
Columns:
customer_id INTEGER PK (declared, enforced)
email VARCHAR
phone VARCHAR
segment VARCHAR
Provenance: catalog only
[shop.orders]
unmeasured: nothing here has been measured yet; figures are declared or drafted
10,000 rows (catalog stats)
Columns:
order_id INTEGER PK (declared, enforced)
customer_id INTEGER
account_id INTEGER
status VARCHAR
created_at VARCHAR
deleted BOOLEAN
Provenance: catalog only
Not shown: no other candidate tables.
context() never spends warehouse money by itself: tables it shows that were never
measured are put on a queue (see Measure).
Measure¶
report = guru.measure("shop.orders") # one table (names and globs accepted)
report = guru.measure(all=True) # every table, hottest first
print(len(report.measured_tables), "tables measured;", report.bytes, "bytes")
for d in report.errors:
print(d.code, d.message)
Measurement runs read-only FactLang probes within a budget (default: 1 GiB per probe, 10 GiB per run). Small tables are measured exactly; tables above 50 GiB (or 500M rows) are sampled and their numbers are labelled as estimates (Sampling).
Measurement needs FactLang's Checker.measure
SchemaGuru requires FactLang 0.1.4 or later, which provides it. With a FactLang build that
lacks it, measure() writes nothing and returns SG304 in report.errors; everything
else keeps working on catalog knowledge.
Add what people know¶
A YAML overlay states what the data cannot: meaning, expected values, soft-delete rules, pitfalls, glossary terms. Expectations are checked against measurement and never rewritten.
for d in guru.load_overlays("schemaguru.yaml"):
print(d.code, d.severity.value, d.message, d.location)
print(guru.context("refund rate by month").text)
The [shop.orders] block of that view, after measurement and the overlay:
[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¶
ok = guru.find_path("shop.payments", "shop.customers")
print([t.canonical() for t in ok.paths[0].tables], ok.paths[0].coverage)
refused = guru.find_path("shop.orders", "shop.events")
print(refused.refusal, "-", refused.explanation)
Hand it to an agent¶
tools = guru.tools() # JSON-schema tool specs
print([t["name"] for t in tools])
result = guru.handle_tool_call("find_join_path", {"from": "orders", "to": "events"})
print(result["text"])
print(guru.prompt_block()[:400]) # a system-prompt fragment
guru.close()
See Agents, tools and MCP for adapters (LangChain, LlamaIndex, OpenAI
Agents, Anthropic) and schemaguru mcp.
The same from the command line¶
schemaguru --url duckdb:///warehouse.duckdb crawl
schemaguru --url duckdb:///warehouse.duckdb measure --all
schemaguru context "monthly revenue by customer segment"
schemaguru path shop.orders shop.events # exit code 1: the route is refused
schemaguru lint schemaguru.yaml # check an overlay
Commands that only read knowledge (context, search, path, report, mcp) work on the
store alone. The full list is in the CLI reference.
Bring your own connection¶
Guru.connect is a convenience. Any metadata executor and measurement backend can be passed
in; here a DuckDB connection you already hold:
import duckdb
from schemaguru.catalog import DBAPIExecutor, reader_for
conn = duckdb.connect("warehouse.duckdb", read_only=True)
mine = sg.Guru(
reader=reader_for("duckdb", DBAPIExecutor(conn)),
store=".schemaguru/mine.db",
dialect="duckdb",
)
print(mine.crawl().tables_seen, "tables crawled")
mine.close()
conn.close()
sg.Guru(connector=...) takes what your project already holds and builds both the catalog
reader and the measurement backend from it: a DB-API connection (duckdb, sqlite3,
psycopg, …; the dialect comes from the driver, or pass dialect=), a SQLAlchemy engine, a
BigQuery client, a FactLang connector, or a plain function execute(sql) /
execute(sql, params) returning rows as dicts (pass dialect=). A function that takes no
parameters gets every value inlined as an ANSI literal. Such an execute(sql) or query(sql)
host has no driver binding, so a probe whose text value holds a backslash, a NUL, a line
terminator (CR, LF, U+0085, U+2028, U+2029), a quote look-alike a non-Unicode code page may
read as ' (U+2018, U+2019, U+201A, U+201B, U+2032, U+02BC, U+FF07) or a backtick (some
dialects read it as an identifier quote), or whose
value is not a plain scalar, is refused (SG109), and its final SQL must pass the read-only guard. On BigQuery, Databricks, Spark,
Hive and any dialect SchemaGuru does not know to double quotes, a text value holding ' is
refused too: their string literals have no doubled-quote form (BigQuery rejects
'O''Brien', Databricks reads it as OBrien). Literals are spelled for the dialect (T-SQL
text as N'…', T-SQL and Oracle booleans as 1/0), and each one is re-checked against
that spelling before the host runs the SQL. Anything FactLang itself declines to inline is
reported as SG109 with the reason. Pass a DB-API
connection, an engine or a BigQuery client for full support. Anything else raises ConfigError SG107
naming the accepted types.