Sqlsure logo

Sqlsure

Semantic SQL inspector: catches double-counting, wrong joins, PII exposure before execution.

Install Sqlsure

Pick your client, then add it in one click or paste the config.

STDIOPython
~/Library/Application Support/Claude/claude_desktop_config.json
claude_desktop_config.json
{
  "mcpServers": {
    "sqlsure": {
      "command": "uvx",
      "args": [
        "sqlsure",
        "--model",
        "<model>"
      ]
    }
  }
}

Settings → Developer → Edit Config, merge this into mcpServers, then fully quit and reopen Claude Desktop.

Claude Code command
claude mcp add --transport stdio sqlsure -- uvx sqlsure --model '<model>'

Run in your terminal. Add --scope project to share it with your team through .mcp.json.

We couldn’t confirm it starts correctly

We ran the install command but it didn't respond within our test window — this can mean a slow first-time install rather than a real problem.

uvx sqlsure --model <model>

Process exited before answering initialize.

This is an experimental automated check and can have false negatives — missing environment variables, a slow cold install, etc. It doesn’t necessarily mean something’s wrong. Last checked .

Overview

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked

Recent health check succeeded.

26/26 checks healthy over the last 88d

Supply-chain signal

No high-severity advisories surfaced by our automated scan.

Critical 0High 0Medium 0Low 0

Scanned 2d ago via OSV.dev · sqlsure (PyPI)

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

GitHub stars100Stargazers on the source repository.
Last commit6d agoMost recent push to the default branch.
Install checkInconclusiveDidn't respond in our test window — often a slow first install.

From the project README

sqlsure

CI PyPI License: Apache-2.0 Python

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 reported upstream and since fixed — BIRD's 2026 Mini-Dev release added exactly the two foreign keys we reported, and its annotations now match the shipped databases on all 11 databases (how we verified).

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

Terminal
pip install sqlsure
server.ts
from sqlsure import SemanticModel, check
violations = check(sql, model)   # [] means semantically safe

Or clone and run the 30-second demo:

bash
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:

bash
python -m sqlsure.cli --model model.json query.sql   # exit 1 on violations

2. MCP server — your AI agent must pass inspection before executing:

Terminal
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)

RuleSeverityCatches
FANOUTerrorSUM/COUNT of additive measure after one-to-many join
CHASMerrortwo+ fan-out joins multiplying each other
ADDITIVITYerrorSUM of a non-additive measure (rates, averages)
SEMI_ADDITIVEerrorbalances/censuses summed across their snapshot dimension
JOIN_KEYerrorjoin on columns matching no declared relationship
CROSS_JOINerrorjoin with no predicate
WEIGHTED_AVGwarningAVG/MEDIAN/STDDEV/percentile re-weighted by fan-out
UNDECLARED_JOINwarningjoin with no declared relationship (unverifiable ≠ safe)
SENSITIVE_COLUMNpolicyPHI/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.json or schema.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.introspect builds the rulebook from the catalog — SQLite PRAGMAs or information_schema PK/FK (postgres/mysql). Introspecting BIRD's own database files recovered 2 foreign keys missing from the benchmark's published schema — reported upstream and fixed in BIRD's 2026 release (bird-bench/mini_dev#37)

    server.ts
    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, relationship joinType + 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

Apache-2.0 · sqlsure.ai

mcp-name: io.github.sqlsure/sqlsure

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about Sqlsure

sqlsure is an MCP server that deterministically inspects SQL against declared semantic facts before execution. It catches risks such as double-counting from fan-out joins, invalid aggregation, unsafe joins, and exposed PHI/PII. It returns machine-actionable fixes so agents can follow a draft–check–fix–check–execute workflow, using dbt-derived model metadata offline.

Add sqlsure with Claude’s MCP command: `claude mcp add sqlsure -- python -m sqlsure.mcp_server --model /abs/path/model.json`. The server uses the specified semantic model to inspect SQL before execution.

sqlsure detects semantic SQL risks including fan-out double-counting, chasm joins, non-additive or semi-additive measures being summed, invalid or undeclared join keys, cross joins without predicates, weighted-average issues, and sensitive PHI/PII columns exposed in query output.

sqlsure uses facts already declared in dbt: `unique` tests establish grain, `relationships` tests describe join cardinality, and `meta` tags identify measures that are safe to sum. These declarations provide the semantic model used for deterministic inspection.

Yes, sqlsure attaches a machine-actionable `fix` to every rejection. An AI agent can apply the fix and repeat the check before execution; the documented benchmark reports that applying fixes verbatim produced a passing query 10 out of 10 times.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewSqlsure AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/sqlsure?style=directory)](https://allmcps.com/mcp/sqlsure)
HTML Embed
<a href="https://allmcps.com/mcp/sqlsure"><img src="https://allmcps.com/api/badge/sqlsure?style=directory" alt="Sqlsure on AllMCPs" /></a>