pypi sqlsurestdioApache-2.0updated 1mo ago
AI writes your SQL. sqlsure makes sure it's right.
What can you do with sqlsure?
sqlsure
AI writes your SQL. sqlsure makes sure it's right.
A query can be perfectly valid, run without error, and return a number that's silently wrong โ revenue double-counted by a join, an average summed, a patient identifier exposed. Databases don't catch this. Linters don't catch this. LLMs reviewing their own SQL don't catch this.
sqlsure does โ deterministically, in 0.1 ms, before the query runs.
Proof, not promises: we ran sqlsure over the gold answers of the two benchmarks every text-to-SQL model is graded on. 2,568 expert-written queries, 45 flags, zero false alarms โ including a BIRD dev gold answer that is provably wrong by 8ร from the exact bug class sqlsure targets, and a schema defect now filed upstream.
How it works
sqlsure judges SQL against facts your team already declared โ dbt unique
tests become grain, relationships tests become join cardinality, one-line
meta tags mark what's safe to sum. No new language to learn, no model to
maintain by hand. Rules are dictionary lookups, not LLM calls: same input,
same verdict, every time, offline.
Every rejection carries a machine-actionable fix, so AI agents
self-repair: draft โ check โ fix โ check โ execute. In our benchmark,
applying the fix verbatim produced a passing query 10/10 times.
Quick start
pip install sqlsure
from sqlsure import SemanticModel, check
violations = check(sql, model) # [] means semantically safe
Or clone and run the 30-second demo:
python check.py # 5 wrong queries rejected, 1 approved โ with fixes
python -m sqlsure.scan path/to/dbt-repo --report report.md # audit any dbt repo
Three doors, one engine
1. CI gate โ blocks the merge when a PR double-counts:
python -m sqlsure.cli --model model.json query.sql # exit 1 on violations
2. MCP server โ your AI agent must pass inspection before executing:
claude mcp add sqlsure -- python -m sqlsure.mcp_server --model /abs/path/model.json
See docs/MCP.md for tool reference and agent-loop patterns.
3. Library โ embed check() inside any text-to-SQL product or agent
framework. A drop-in SemanticGate wraps
Vanna/WrenAI-style generators; a
semantic eval metric scores NL2SQL output
where execution-accuracy is blind.
Also available as an Agent Skill โ a single SKILL.md your agent loads directly; no server process needed.
The rules (v0.1)
| Rule | Severity | Catches |
|---|---|---|
| FANOUT | error | SUM/COUNT of additive measure after one-to-many join |
| CHASM | error | two+ fan-out joins multiplying each other |
| ADDITIVITY | error | SUM of a non-additive measure (rates, averages) |
| SEMI_ADDITIVE | error | balances/censuses summed across their snapshot dimension |
| JOIN_KEY | error | join on columns matching no declared relationship |
| CROSS_JOIN | error | join with no predicate |
| WEIGHTED_AVG | warning | AVG silently re-weighted by fan-out |
| UNDECLARED_JOIN | warning | join with no declared relationship (unverifiable โ safe) |
| SENSITIVE_COLUMN | policy | PHI/PII column exposed in query output |
When sqlsure can't verify something, it says "can't verify" โ never "looks fine." Honest uncertainty is a feature.
Trust properties
- Deterministic โ same SQL + same rulebook = same verdict, always; rules are dictionary lookups, auditable line by line
- Offline โ zero network calls; your SQL never leaves your machine
- No data access โ parses query text; never connects to a database
- No telemetry โ nothing collected, ever (SECURITY.md)
- Supply chain โ releases ship exclusively via PyPI Trusted Publishing (OIDC) from tagged commits with public CI runs; two runtime deps
Where the rulebook comes from
-
dbt (works today):
manifest.jsonorschema.ymlโ the tests teams already wrote become enforceable semantics, zero config -
Plain PK/FK declarations (works today โ powered the benchmark audits)
-
The live database itself (works today): no semantic layer at all?
sqlsure.introspectbuilds the rulebook from the catalog โ SQLite PRAGMAs orinformation_schemaPK/FK (postgres/mysql). Introspecting BIRD's own database files recovered 2 foreign keys missing from the benchmark's published schema (bird-bench/mini_dev#37)from sqlsure.introspect import model_from_sqlite model = model_from_sqlite("app.db") # PK -> grain, FK -> join edges -
Hand-written JSON โ model.example.json
-
OSI and WrenAI MDL (working loaders in integrations/): OSI demonstrated on the spec's published examples; WrenAI MDL demonstrated on WrenAI's own shipped example manifest โ
primaryKeyโ grain, relationshipjoinType+conditionโ join edges, cube measures โ additivity -
Cube, Snowflake Semantic Views โ adapters on the roadmap; the engine only ever sees one
SemanticModel
Validated on
- 16/16 rule tests, 100% recall / 0% false positives on the paired benchmark (docs/METRICS.md)
- Real production repos (Mattermost's warehouse, Fivetran packages, dbt's jaffle shop) โ docs/TEST-REPORTS.md
- Spider + BIRD gold queries โ the zero-noise external audit above
Learn more
- docs/EVIDENCE.md โ what it does for you, every claim linked to a rerunnable measurement
- docs/ARCHITECTURE.md โ how it physically works, ELI5 โ god level, with real intermediate outputs
- docs/FOR-DUMMIES.md โ every concept from zero
- docs/INTEGRATIONS.md โ GitHub Action, pre-commit, MCP, Snowflake UDF / Cortex Agent tool, query-history audit
- docs/MCP.md โ MCP server documentation
- CONTRIBUTING.md โ adding rules and loaders
Apache-2.0 ยท sqlsure.ai
mcp-name: io.github.sqlsure/sqlsure
Install
Add sqlsure to your client. Pick the one you use.
claude mcp add sqlsure -- uvx sqlsurecodex mcp add sqlsure -- uvx sqlsureamp mcp add sqlsure -- uvx sqlsure{
"mcpServers": {
"sqlsure": {
"command": "uvx",
"args": [
"sqlsure"
]
}
}
}Add to `claude_desktop_config.json`, then restart Claude Desktop.
{
"mcpServers": {
"sqlsure": {
"command": "uvx",
"args": [
"sqlsure"
]
}
}
}Add to `~/.cursor/mcp.json`, or `.cursor/mcp.json` for a single project.
code --add-mcp '{"name":"sqlsure","command":"uvx","args":["sqlsure"]}'Or add the block manually to `.vscode/mcp.json` under `servers`.
{
"mcpServers": {
"sqlsure": {
"command": "uvx",
"args": [
"sqlsure"
]
}
}
}Add to `~/.codeium/windsurf/mcp_config.json`.
{
"mcpServers": {
"sqlsure": {
"command": "uvx",
"args": [
"sqlsure"
]
}
}
}Add to `cline_mcp_settings.json` via the MCP Servers panel.
{
"mcpServers": {
"sqlsure": {
"command": "uvx",
"args": [
"sqlsure"
]
}
}
}Add to `~/.gemini/settings.json`.
{
"mcpServers": {
"sqlsure": {
"type": "local",
"command": "uvx",
"args": [
"sqlsure"
],
"tools": [
"*"
]
}
}
}Add to `~/.copilot/mcp-config.json`, or run `/mcp add` inside the CLI.
{
"context_servers": {
"sqlsure": {
"command": {
"path": "uvx",
"args": [
"sqlsure"
]
}
}
}
}Add to your Zed `settings.json`.
uvx sqlsureRun `goose configure`, choose **Add Extension โ Command-line Extension**, and paste this command.
Score
39 / 100
Incomplete
- Documentation25/25
- Maintenance16/25
- Trust16/20
- Capability0/15
- Install experience12/15
- Documents what it does and how to connect
- Has a resolvable package or endpoint
- Exposes at least one tool, prompt or resource
- README has substantive content
- Includes a code example
- Documents its configuration
- Mentions credentials or security posture
- Last commit 44 days ago
- Has a release history
- Repository is not archived
- Licensed Apache-2.0
- Namespace verified in the official MCP registry
- Claimed by its owner
- Published under an organisation
- 0 tool(s) documented
- Provides prompt templates
- Provides resources
- 12 documented install method(s)
- Published to a package registry
- Offers a hosted endpoint โ no local install
Version history
| Versions | Published |
|---|---|
| 0.1.1Latest | Jul 3, 2026 |