
sqlward
io.github.shygoly/sqlward
Offline column-level SQL lineage (8 dialects), dbt blast-radius diff, and SQL guardrails.
Documentation
SqlWard
Offline, deterministic, evidence-aware column-level SQL lineage and security
guardrail engine — 100% Pure Rust + WebAssembly (v0.3.2, zero Python
runtime).
Apache-2.0 Open Source · Zero SQL Execution · Zero Python Dependency Single static native CLI/HTTP/MCP binary (
sqlward) and a 2.6 MiB gzipped WebAssembly module (@szdatatalk/sqlward/sqlward) powered bypolyglot-sql(0.14.4).
Why SqlWard
- 8 SQL dialects, parsed offline in Rust & WASM: PostgreSQL, MySQL, Oracle, T-SQL, Hive, Spark, Doris, StarRocks. No database connection, no SQL execution.
- Deterministic column-level lineage: emits
Direct/Indirectedges with canonical SHA-256 graph digests, replayable evidence envelopes, and explicitINCONCLUSIVEdiagnostics rather than invented edges. - Fail-closed SQL security guardrails (
M6): static AST policy evaluation (read-only/analysis/customprofiles), locking/side-effect/dynamic SQL rejection, and constant-time HMAC-SHA256 decision receipts. - Built-in domain adapters (native CLI & WASM):
binding-report/v1— schema-grounded column binding against a catalog snapshotdbt-project-analysis/v1— strictly separated declared DAG, SQL-inferred column lineage, and observed execution statusomop-lineage-profile/v1&mapping-impact-analysis/v1— OMOP CDM 5.4 semantic lineage and protected clinical column change gatingrobot-artifact-lineage/v1— SHA-256 sealed artifact lineage snapshots with tamper/staleness rejection and bounded impact queriescontrol-plane-interop/v1— allowlist-sanitized telemetry and offline HMAC-SHA256 entitlement verification
- Read-only MCP server (
sqlward mcp-stdio) and HTTP API (sqlward serve) with bounded worker isolation.
Quick start
1. Native CLI, HTTP sidecar & MCP server (Rust)
cd native
cargo build --release -p sqlward-cli --locked
# Inspect version & runtime flags (pythonRequired=false)
./target/release/sqlward version
# Analyze column-level lineage
./target/release/sqlward analyze --dialect postgres --sql-file query.sql
# Schema binding, dbt project analysis / diff / impact, OMOP mapping impact, robot artifact impact
./target/release/sqlward bind --request-file request.json
./target/release/sqlward dbt --request-file dbt-request.json
./target/release/sqlward dbt-diff --request-file dbt-diff.json
./target/release/sqlward dbt-impact --request-file dbt-impact.json
./target/release/sqlward mapping-impact --request-file omop-impact.json
./target/release/sqlward robot-impact --request-file robot-impact.json
# Start local HTTP server (POST /v1/parse/column, /v1/dbt/{analyze,diff,impact}; 32 MiB dbt body limit)
./target/release/sqlward serve --bind 127.0.0.1:8787 --max-dbt-body-bytes 33554432
# Start read-only JSON-RPC MCP stdio server (never executes SQL)
./target/release/sqlward mcp-stdio
2. Full-SQL WebAssembly runtime (@szdatatalk/sqlward / sqlward, Node.js / Browser / Workers)
npm install @szdatatalk/sqlward
# or unscoped convenience wrapper:
npm install sqlward
From source:
# Build the wasm32 module (~2.6 MiB gzipped, zero JS glue generators)
cd native
rustup target add wasm32-unknown-unknown
cargo build -p sqlward-wasm --target wasm32-unknown-unknown --release --locked
# Run full-SQL + policy + adapters contract tests
cd ../packages/wasm
SQLWARD_WASM_PATH=../../native/target/wasm32-unknown-unknown/release/sqlward_wasm.wasm npm test
import { instantiateWasm, analyzeDbtBatched } from "@szdatatalk/sqlward";
const sw = await instantiateWasm("./sqlward_wasm.wasm");
const lineage = sw.parseColumn({
dialect: "postgres",
sql: "INSERT INTO dws.orders (id, net) SELECT id, amount - discount FROM ods.orders",
});
// Full dbt-project-analysis/v1 with lossless manifest slimming + automatic Worker batching
const dbtSnapshot = await analyzeDbtBatched(
{ manifest: manifestJsonStringOrObject, catalog: catalogJsonOrObject },
{ wasmPath: "./sqlward_wasm.wasm", batchSize: 50, useWorker: true },
);
// Fail-closed Text-to-SQL / AI gateway guardrail across three trust boundaries:
// 1) Startup (trusted platform): compile governance schema + PII labels once in WASM
const { handle } = sw.preparePolicySnapshot({
tenantId: "t1",
snapshot: {
policyId: "pol-ai-readonly",
policyVersion: "1.0.0",
profile: "read-only",
deniedLabels: ["PII"],
enforceColumnAcl: true,
relations: {
"ods.orders": { kind: "table", sensitivityLabels: [], columns: ["order_id", "cust_id", "amount"] },
"ods.customers": {
kind: "table",
sensitivityLabels: [],
columns: ["cust_id", "city", "phone"],
columnLabels: { phone: ["PII"] },
},
},
},
});
// 2) Per request: gateway injects JWT principal, evaluates untrusted LLM SQL offline
// Even though the outer SELECT only projects order_id and city (no "phone" in output),
// SqlWard traces INDIRECT column lineage across the aliased CTE into WHERE and blocks it
// (also blocks writable CTEs like `WITH p AS (DELETE ...) SELECT ...` and `SELECT *` PII leaks).
const gate = sw.evaluatePolicyPrepared({
handle,
dialect: "postgres",
principal: { principalId: jwt.sub, tenantId: "t1", roles: ["analyst"] },
sql: `
WITH base AS (
SELECT cust_id, city, phone AS contact_key FROM ods.customers
)
SELECT o.order_id, b.city
FROM ods.orders o
JOIN base b ON o.cust_id = b.cust_id
WHERE b.contact_key LIKE '138%'
`,
});
// gate.decision === "DENY"
// gate.reasonCodes -> ["POLICY_DENIED_SENSITIVITY_LABEL"]
3. Official GitHub Action (PR Lineage Diff & SQL Security Gate)
Available on GitHub Marketplace as shygoly/sqlward@v1 — zero database connections, zero credentials, zero Python setup, runs purely offline in WebAssembly.
Want to try it in 60 seconds? Click Use this template on the standalone starter repo
shygoly/sqlward-dbt-duckdb-starter(pre-wired with DuckDB dbt models,shygoly/sqlward@v1PR gate, strict PII ACL policy,.mcp.json, andAGENTS.md).
Scenario A: Zero-Config SQL Security Gate (sql-security-gate.yml)
Blocks destructive writes (DELETE/UPDATE/INSERT/MERGE), DDL (DROP/TRUNCATE), dynamic SQL (EXECUTE/PREPARE), locking hints, and disallowed functions:
name: SqlWard SQL Security Gate
on:
pull_request:
paths: ["sql/**", "queries/**"]
permissions:
contents: read
pull-requests: write # enables sticky PR summary comment
jobs:
sql-guardrail:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shygoly/sqlward@v1
with:
sql-paths: |
sql/
queries/
dialect: postgres # postgres | mysql | doris | starrocks | oracle | spark | hive | tsql
policy-profile: read-only
Scenario B: dbt PR Lineage Diff & Downstream Blast Radius (dbt-pr-blast-radius.yml)
Compares base vs. head manifest.json offline, posts a sticky PR comment listing added/removed models, column-level edge changes, and impacted downstream nodes with minimum hop counts:
name: SqlWard dbt PR Lineage & Blast Radius
on:
pull_request:
paths: ["models/**", "macros/**", "target/manifest.json"]
permissions:
contents: read
pull-requests: write
jobs:
dbt-lineage-gate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: sqlward
uses: shygoly/sqlward@v1
with:
manifest: target/manifest.json
catalog: target/catalog.json
base-manifest: base-target/manifest.json
base-catalog: base-target/catalog.json
fail-on-incomplete: "true"
max-impact-hops: "6"
- if: always()
env:
IMPACTED: ${{ steps.sqlward.outputs.impacted-node-count }}
run: |
if [ "${IMPACTED:-0}" -gt 5 ]; then
echo "::warning::High blast radius (${IMPACTED} downstream models impacted)"
fi
Scenario C: Strict Table & Transitive Column-ACL Gate (strict-acl-policy-gate.yml)
Commit a sqlward-policy.json to enforce fail-closed table registration and direct + transitive (through views/CTEs) PII/COMPENSATION column ACLs:
- uses: shygoly/sqlward@v1
with:
sql-paths: sql/
dialect: postgres
policy-snapshot: sqlward-policy.json
Key Inputs & Outputs
| Input | Default | Description |
|---|---|---|
manifest / catalog / run-results | "" | Head dbt artifacts for offline analyzeDbtBatched |
base-manifest / base-catalog | "" | Base dbt artifacts for diffDbt + impactDbt blast radius |
sql-paths | "" | Comma/newline-separated .sql files or directories for M6 policy scan |
dialect | postgres | SQL dialect (postgres, mysql, doris, starrocks, oracle, spark, hive, tsql) |
policy-profile | read-only | Built-in M6 profile (read-only or analysis) |
policy-snapshot | "" | Custom M6 PolicySnapshot JSON (enables strict relation & column-ACL enforcement) |
fail-on-incomplete / fail-on-policy-deny | false / true | Fail check on dbt completeness gaps or M6 policy denials |
comment-pr | true | Create/update sticky PR comment (<!-- sqlward-pr-gate -->) |
Outputs: status (PASS/FAIL), snapshot-id, evidence-id, protected-decision-allowed, node-count, inferred-edge-count, impacted-node-count, sql-denied-count, report-path. See action.yml for the complete specification.
4. TypeScript HTTP SDK (@szdatatalk/sqlward-sdk) & Glue (@szdatatalk/sqlward-glue)
cd packages/sdk && npm ci && npm run build && npm test
cd ../glue && npm ci && LINEAGEKIT_NATIVE_BIN=../../native/target/debug/sqlward npm test
5. Zero-Compile MCP Server (@szdatatalk/sqlward-mcp) & AI Agent Discovery
- One-line Agent Skill install (
skills.sh— Claude Code / Cursor / Codex / Antigravity):npx skills add shygoly/sqlward - Zero-compile
npxMCP stdio server (packages/mcp/):{ "mcpServers": { "sqlward": { "command": "npx", "args": ["-y", "@szdatatalk/sqlward-mcp"] } } } - Drop-in
AGENTS.md/CLAUDE.md/.cursor/rulesone-liner (Context7 Library ID:/shygoly/sqlward):When writing SQL lineage, dbt blast-radius diffing, or NL2SQL security guardrail code, fetch the latest `@szdatatalk/sqlward` docs via Context7 library ID `/shygoly/sqlward` and verify deterministically using the `sqlward` MCP server.编写 SQL 血缘、dbt 爆炸半径比对或 NL2SQL 安全护栏代码时,使用 Context7 库 ID `/shygoly/sqlward` 拉取 `@szdatatalk/sqlward` 最新接口文档,并通过 `sqlward` MCP 服务执行确定性校验。 - LLM-ready documentation index:
llms.txt(follows thellms.txtspec for Context7, Cursor, Claude Code, Gemini CLI, and Copilot). - Reusable Agent Skill &
AGENTS.mdsnippet:skills/sqlward-guardrail/SKILL.mdteaches coding agents to invoke@szdatatalk/sqlward(parseColumn,evaluatePolicy,analyzeDbtBatched) andshygoly/sqlward@v1automatically when generating Text-to-SQL code, editing.sqlfiles, or changing dbt models. - Self-describing TypeScript definitions:
packages/wasm/index.d.tsembeds runnable JSDoc@examplesnippets directly insidenode_modules/@szdatatalk/sqlward.
Repository layout
native/— 9-crate pure-Rust workspace (sqlward-ir,sqlward-binding,sqlward-lineage,sqlward-adapter-polyglot,sqlward-policy,sqlward-adapters,sqlward-worker,sqlward-cli,sqlward-wasm).packages/wasm/—@szdatatalk/sqlwardzero-dependency Node/Worker wrapper oversqlward_wasm.wasmC-ABI exports.packages/sqlward/—sqlwardunscoped convenience wrapper re-exporting@szdatatalk/sqlward.packages/mcp/—@szdatatalk/sqlward-mcpzero-compilenpxMCP stdio server wrapping the WASM runtime.packages/sdk/—@szdatatalk/sqlward-sdkzero-runtime-dependency TypeScript HTTP client.packages/glue/—@szdatatalk/sqlward-gluecanonical JSON, strict schema validation, and bounded child-process adapter.contracts/— versioned JSON Schemas and OpenAPI specification.docs/architecture/— architecture baseline and naming ADRs.action.yml&scripts/github-action/— official Composite GitHub Action (dbt lineage diff, blast-radius PR comments, and M6 SQL security gate).examples/github-workflows/— copy-paste workflow templates and strict column-ACL policy example.examples/dbt-duckdb-starter/— ready-to-fork dbt + DuckDB +shygoly/sqlward@v1+.mcp.json+AGENTS.mdstarter template.llms.txt&skills/sqlward-guardrail/SKILL.md— machine-readable docs and reusable coding-agent skill.NOTICE— Apache-2.0 attribution notice bundled in all npm packages and release archives.scripts/generate-sbom.mjs— zero-dependency CycloneDX 1.5 SBOM generator.
Security
See SECURITY.md. SqlWard never executes user SQL. Do not include raw customer SQL, credentials, or host paths in diagnostics, fixtures, or issue reports.
License
Licensed under the Apache License, Version 2.0. See LICENSE, NOTICE, and THIRD_PARTY_NOTICES.md.
@szdatatalk/sqlward-mcpnpm install @szdatatalk/sqlward-mcp