Schemap
The local semantic compiler for AI agents working with real databases.
Compile schema semantics, relationships, and database invariants into deterministic agent context.
Verify generated SQL before it executes.
⚡ The Architecture: Grounding → Generation → Verification
AI coding assistants (Cursor, Claude Code, Windsurf, Codex) are fluent in SQL syntax, but fail at production relational databases because raw schema DDL omits implicit operational invariants:
SCHEMAP 4.0
┌─────────────────┐
│ Database Schema │
└────────┬────────┘
│ (Introspect tables, FKs, types)
▼
┌─────────────────────┐
│ Semantic Compiler │
│ │
│ • Entity Roles │
│ • Measure Units │
│ • Join Graphs │
│ • Tenant Invariants │
│ • Lifecycle Rules │
│ • Provenance Tags │
└─────────┬───────────┘
│
▼
GroundedPlan
│ (Provided to LLM via MCP or CLI)
▼
┌─────────────────────┐
│ AI Coding Agent │
│ (Claude, Cursor, │
│ Gemini, Codex) │
└─────────┬───────────┘
│
▼
Generated SQL
│
▼
┌─────────────────────┐
│ AST Policy Engine │
│ │
│ • Mutation blocking │
│ • Tenant validation │
│ • Soft-delete check │
│ • Cartesian hazard │
└─────────┬───────────┘
│
ALLOW / REJECT / RE-VALIDATE
│
▼
Database Execution
🛑 The Problem: The Hidden Traps of Naked Schema Prompts
In production databases, queries fail not from syntax errors, but from missing invariants:
- The "Cents Illusion": Models sum integer currency columns (
amount_cents), reporting $19,900.00 instead of $199.00 ($100\times$ metric distortion). - Zombie Records: Soft-deleted records and cancelled subscriptions (
deleted_at IS NOT NULLoris_deleted = TRUE) are counted as active data. - Tenant Data Leaks: Multi-table joins drop tenant predicates (
org_id), leaking neighboring customer records. - Cartesian Hazards: Disconnected joins (
FROM invoices, plans) produce accidental Cartesian products. - Destructive Operations: Agents generate
DELETEorDROP TABLEqueries without execution safeguards.
🚀 Quick Start: Model Context Protocol (MCP)
Schemap exposes three native MCP tools for Cursor, Claude Code, and Windsurf.
1. Configure MCP Server
Add Schemap to your claude_desktop_config.json or .cursor/mcp.json:
{
"mcpServers": {
"schemap": {
"command": "uvx",
"args": ["schemap-tool", "mcp"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/production_db"
}
}
}
}
Zero YAML required. Schemap inspects the database connection locally and provides three tools:
| Tool | Phase | Function |
|---|---|---|
schemap_ground |
Before writing SQL | Resolves target tables, foreign-key join paths, monetary measures, and tenant invariants with explicit provenance ([DECLARED] vs [INFERRED]). |
schemap_verify |
Before executing SQL | Deny-by-default AST policy circuit breaker that blocks mutations (DELETE, DROP, UPDATE), Cartesian products, and tenant omissions. |
schemap_patch |
Remediating SQL | Injects missing tenant and soft-delete filters, then re-validates the patched AST to ensure no hazards remain. |
💻 CLI Usage
For terminal workflows, scripts, and local pair-programming:
# 1. Ground an analytical question before writing SQL
schemap ground "What was Org 42's revenue last month?" --db "$DATABASE_URL" --tenant-id 42
# 2. Verify SQL before executing against production
schemap verify "SELECT * FROM orders" --db "$DATABASE_URL" --tenant-id 42
# 3. Patch missing invariants with safety re-verification
schemap patch "SELECT * FROM orders" --db "$DATABASE_URL" --tenant-id 42
🔬 Evidence & Evaluation
Schemap maintains three canonical evaluation documents separating live model reasoning, controlled policy verification, and domain generalization:
1. Master Methodology & Headline Results — EVALUATION.md
- Analytical Success: In our 500-task controlled benchmark on seeded operational schemas, the raw-schema baseline achieved 10.6% first-pass analytical success versus 90.0% with Schemap grounding.
- Destructive Operation Blocking: Schemap blocked 100% of unsafe operations tested in our mutation suite (0 escapes).
- Decoupled Denominators: Analytical correctness and mutation safety are independently measured.
2. Live Model-in-the-Loop Evaluation — LIVE_MODEL_EVALUATION.md
- Evaluates live completions from Gemini 3.8 Flash executing against a seeded SQLite operational database.
- Exact Dataset Match: Lifted from 2/8 (25%) on raw DDL to 8/8 (100%) with Schemap grounding.
- Safety Gate: Unguarded models produced 2 destructive mutations;
schemap_verifyblocked 2/2.
3. Cross-Domain Generalization — GENERALIZATION.md
- Evaluates heuristic convention discovery across 6 non-SaaS domains (E-Commerce, Fintech Ledger, Healthcare EHR, Education LMS, HR & Payroll, IoT Fleet).
- Implements a three-tier provenance model:
DECLARED: Explicit constraints defined in DDL or configuration.INFERRED: Recovered via structural conventions (e.g._cents,_id, timestamps).UNKNOWN: Flagged ambiguities (e.g., dual foreign keys between the same tables) requiring human declaration.
🗄️ Supporting Tools & Capabilities
Beyond real-time MCP grounding, Schemap includes tools for local repo maintenance:
- Static Agent Context:
schemap contextcompiles a token-compressedschemap_database_context.md. - Agent Rule Files:
schemap agentsgenerates synchronizedCLAUDE.md,AGENTS.md, and.cursorrules. - Schema Health Diagnostic:
schemap doctoraudits missing foreign keys, orphan tables, and naming consistency. - Supported Databases: PostgreSQL, MySQL, SQLite, Turso / libSQL, Oracle.
📄 License & Community
Schemap is licensed under the MIT License.
- Website: schemap-tool.pages.dev
- Issues & Contributions: github.com/alansyahmi/Schemap
Metadata
Release files for schemap-tool 4.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| schemap_tool-4.0.1.tar.gz | 271.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| schemap_tool-4.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 369.6 kB
Release files / schemap_tool-4.0.1.tar.gz
| Download URL | schemap_tool-4.0.1.tar.gz |
|---|---|
| Size | 271.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
33c9e5e630ac321dd0fab8d62ad300a66f03303606ce8582162abc5df0866c17
|
|
BLAKE2b-256 checksum How to use checksums |
4435d730227a20b28bb90169b61e4c803c65f4026a37f64594122ef1bea61dfe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.1
|
Release files / schemap_tool-4.0.1-py3-none-any.whl
| Download URL | schemap_tool-4.0.1-py3-none-any.whl |
|---|---|
| Size | 97.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f34eedac188635d6dbb64105836261a5b62ee58ca1c1140aa793f49618810db3
|
|
BLAKE2b-256 checksum How to use checksums |
2eee464d03b8629783f3dbe56baa240682db2b1565c2375592baa0331c748fa1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.1
|