Sqlsure

io.github.sqlsure由 GitHub 账号 sqlsure 发布v0.1.1更新于 Oct 24, 2026

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

概览

AI 生成的概览

一个本地 MCP 服务器,在执行前按已声明的语义规则检查 AI 编写的 SQL,标记重复计数、错误连接和 PII 暴露。

可以做什么
依据由 dbt 测试、主外键声明、数据库内省或手写 JSON 构建的语义模型检查 SQL 文本,返回违规项及可机器执行的修复建议,让智能体先起草、检查、修复、再检查后执行。识别一对多连接导致的扇出与多重扇出、非可加或半可加度量、未声明或缺失的连接键、无谓词交叉连接、被重新加权的平均值以及敏感 PHI/PII 列。对无法验证的查询如实报告“无法验证”,而不是判定为安全。审计整个 dbt 仓库并生成报告。
适用场景
当助手为分析场景生成 SQL,而你希望在执行前以确定性方式排查静默错误的数字或暴露的敏感列时使用,尤其适合已在 dbt 或主外键元数据中声明粒度与关系的团队。
运行要求
以 Python 包通过 pip 安装,作为本地 stdio 进程运行;需要 Python,并在启动时传入语义模型文件,该文件可由 dbt manifest 或 schema 文件、主外键声明、数据库目录内省或手写 JSON 构建。无需账号、API 密钥或网络访问。
安装前请注意
它只解析查询文本,不连接数据库,因此只能确认查询符合已声明规则,无法确认结果正确;未声明的关系会被报告为无法验证而非安全。模型文件需保持准确,敏感列策略依赖你自己的标记。据称无遥测、无网络调用。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Sqlsure,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

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

bash
pip install sqlsure
python
from sqlsure import SemanticModel, checkviolations = 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 fixespython -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:

bash
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 silently 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 (bird-bench/mini_dev#37)

    python
    from sqlsure.introspect import model_from_sqlitemodel = 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

来源:README.md,提交 d1b98e7

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.1最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分