Skip to main content

Database metadata compiler for AI agent consumption

Project description

dbook

A database metadata compiler that makes AI agents understand your database — not just its structure, but its meaning.

dbook compiles your database schema into AI-ready metadata — enum values, semantic relationships, example queries, auto-detected metrics, data lineage, and PII markers. In SQL execution benchmarks, agents with dbook produce 100% correct SQL vs 75% with raw DDL.

The Problem

Your AI agents are blind to your data.

Raw DDL tells agents the structure — but not the meaning:

  • status VARCHAR(20) — agents guess "active", "enabled", "1"... the real values are "pending", "shipped", "delivered"
  • user_id INTEGER REFERENCES users(id) — but what IS this relationship? The customer? The assignee? The creator?
  • Your gold layer exists because consumers couldn't read silver — but AI agents CAN, with the right metadata

The result:

  • You maintain expensive gold layer ETL just for AI consumption
  • Every agent re-discovers the schema independently (10 agents = 10x cost)
  • Schema changes break agents silently — no one knows until production fails
  • Agents access PII columns unknowingly — compliance risk with every query
  • Agents guess enum values and write wrong SQL — silent data quality issues

What dbook Does

Connects to any database, introspects the schema, and generates structured metadata that gives agents the context DDL lacks:

dbook Architecture

pip install dbook
dbook compile "postgresql://user:pass@host/db" --output ./my_dbook

What agents get:

1. Enum value documentation — auto-detected via SELECT DISTINCT

status: pending, confirmed, shipped, delivered, cancelled
method: credit_card, debit_card, paypal, bank_transfer

2. Semantic FK descriptions — agents understand relationships

→ users via user_id — the customer who placed this order
← order_items.order_id — line items in this order

3. Example queries — patterns agents can follow

- By status: SELECT * FROM orders WHERE status IN ('pending', 'confirmed')
- Revenue over time: SELECT DATE(created_at), SUM(total) FROM orders GROUP BY DATE(created_at)

4. Auto-detected metrics — common aggregations ready to use

- Total Amount: SELECT SUM(total) FROM orders
- Count by Status: SELECT status, COUNT(*) FROM orders GROUP BY status
- Amount over time: SELECT DATE(created_at), SUM(total) FROM orders GROUP BY DATE(created_at)

5. Data lineage — how tables connect in the data flow

Source tables: users, products (no dependencies)
Intermediate: orders → depends on users | ← used by order_items, invoices
Leaf: payments → depends on invoices

6. PII detection — marks sensitive columns, redacts sample data

| email | VARCHAR(255) | EMAIL (0.90) | high |
| card_last_four | VARCHAR(4) | CREDIT_CARD_PARTIAL (0.70) | low |

7. Query validation — SQLGlot-powered, catches errors before execution

validator = QueryValidator(book)
result = validator.validate("SELECT * FROM orders WHERE status = 'completed'")
# Warning: 'completed' not in known values: pending, confirmed, shipped, delivered, cancelled

Key Benchmark Results

SQL Execution Benchmark: DDL vs dbook

Tested on an Amazon-like e-commerce database (34 tables, 15 business tasks, 4 agent types):

Fact Type Raw DDL Base dbook LLM dbook
Structural (column names) 100% 100% 100%
Value-level (enum values) 21% 88% 94%
Overall key fact coverage 76% 96% 98%
SQL execution correctness 75% 100% 100%

In the SQL execution benchmark, dbook achieves 100% correct SQL vs 75% with raw DDL — the difference between agents that guess enum values and agents that know them.

On a 5-table database:

  • DDL key fact coverage: 69% -> dbook: 93% (+24% improvement)
  • SQL execution benchmark: DDL produces 75% correct SQL -> dbook: 100% correct SQL

Agent Discovery (business-term search):

  • 15 real business tasks (billing, sales, support, analytics agents)
  • All 3 modes achieve 15/15 success with mechanical aliases
  • Business terms like "shopping cart", "refund", "A/B test" correctly map to tables

Token Savings (at scale):

  • 50 tables: ~50% fewer tokens per query vs reading all DDL
  • Scales linearly — larger databases see larger savings

Architecture

SQLAlchemy Inspector → BookMeta → Compiler → Output Directory
                                     ↓
                      NAVIGATION.md    (table overview + lineage)
                      schemas/
                        {schema}/
                          _manifest.md  (schema details + relationships)
                          {table}.md    (columns, values, FKs, metrics, examples)

Catalog Protocol

Database-agnostic via Catalog protocol. Default SQLAlchemyCatalog supports any SQLAlchemy-compatible database. DB type auto-detected from URL.

Supported Databases

PostgreSQL, MySQL, SQLite, Snowflake, BigQuery — any database with a SQLAlchemy dialect.

Usage

Full compile

dbook compile "postgresql://user:pass@host/db" --output ./my_dbook

With PII detection (marks sensitive columns, redacts sample data)

pip install dbook[pii]
dbook compile "postgresql://..." --output ./my_dbook --pii

With LLM enrichment (semantic summaries, concept aliases)

pip install dbook[llm]
dbook compile "postgresql://..." --output ./my_dbook --llm --llm-provider anthropic --llm-key sk-...

Check for schema changes

dbook check ./my_dbook "postgresql://user:pass@host/db"

Incremental recompile (only changed tables)

dbook compile "postgresql://..." --output ./my_dbook --incremental

Python API

from dbook.catalog import SQLAlchemyCatalog
from dbook.compiler import compile_book
from dbook.validator import QueryValidator

# Compile
catalog = SQLAlchemyCatalog("postgresql://user:pass@host/db")
book = catalog.introspect_all()
compile_book(book, "./my_dbook")

# Validate agent SQL
validator = QueryValidator(book)
result = validator.validate("SELECT * FROM orders WHERE status = 'delivered'")
print(result.valid, result.errors, result.warnings)

Optional Features

Feature Install Flag What it adds
PII detection pip install dbook[pii] --pii Column sensitivity markers, sample data redaction
LLM enrichment pip install dbook[llm] --llm Semantic summaries, concept aliases, schema narratives
Metrics pip install dbook[metrics] --metrics User-defined canonical business metrics

The Silver Layer Insight

Traditional data pipelines create gold layers because consumers can't read raw data. With dbook, AI agents can understand silver directly — reducing the need for gold views for discovery and ad-hoc queries.

The Silver Layer Insight

Note: dbook reduces the need for gold views for discovery and ad-hoc queries. Gold layers still provide value for: enforced business rules, canonical metric definitions, data quality guarantees, and grain standardization. For critical metrics, define them in metrics.yaml — dbook includes them in its output so agents use the canonical definition, not their own interpretation.

Development

pip install -e ".[dev]"
pytest tests/ -q --tb=short

118 tests covering: introspection, compilation, CLI, PII detection, LLM enrichment, query validation, and realistic agent simulation benchmarks.

License

Apache License 2.0

Project details


Download files

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

Source Distribution

dbook-0.1.0.tar.gz (117.8 kB view details)

Uploaded Source

Built Distribution

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

dbook-0.1.0-py3-none-any.whl (60.5 kB view details)

Uploaded Python 3

File details

Details for the file dbook-0.1.0.tar.gz.

File metadata

  • Download URL: dbook-0.1.0.tar.gz
  • Upload date:
  • Size: 117.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbook-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e4a0b6aa4a2b9bf3202be33cf5a140c29e41c2aa4b051b92903b8aed919cf557
MD5 b565fa68fa25e7b5b232e7309bca12aa
BLAKE2b-256 3f24a2c7970ec61d8ede5dd124cf9120cee10ad9a9c5f9631cb1260676953c85

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbook-0.1.0.tar.gz:

Publisher: publish.yml on ShurikM/dbook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dbook-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dbook-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 60.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbook-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d71aef69522f21db1c702c8920176cbfb121bb5141d677cfb46969448b51b1f
MD5 af33f0b5731b26464fca459158c8f2a2
BLAKE2b-256 38ad614ed8f1f9fe8926d092fae308bed2079b7030d73956e59b594f8d754c9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbook-0.1.0-py3-none-any.whl:

Publisher: publish.yml on ShurikM/dbook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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