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 分