Detect semantic SQL changes and estimate deterministic risk.
Project description
Semantic Risk Engine
Detect semantic SQL changes and compute deterministic risk classifications.
Installation
pip install semantic-risk-engine
# or with uv
uv add semantic-risk-engine
Python API quickstart
from semantic_engine import DiffEngine, RiskEngine
old_sql = "SELECT id, name FROM users WHERE active = 1"
new_sql = "SELECT id FROM users"
diff = DiffEngine().diff(old_sql, new_sql, dialect="snowflake")
report = RiskEngine().compute_risk(diff)
for item in report.high:
print(f"HIGH: {item.change.identifier}")
print(f" {item.reason}")
For type annotations, import from semantic_engine.models:
from semantic_engine.models import SemanticDiff, RiskReport, RiskItem, Change
How it works
SQL is parsed into a sqlglot AST and extracted into a normalized SemanticModel (tables, joins, columns, filters, aggregations, window functions, CTEs, subqueries). Two SemanticModels are diffed to produce a SemanticDiff — a structured list of semantic changes. Each change is classified into HIGH / MEDIUM / LOW / INFO risk based on data-contract impact rules. No query execution, no database connections — pure static analysis.
CLI
semantic-risk-engine diff old.sql new.sql
semantic-risk-engine diff old.sql new.sql --dialect bigquery
Options:
--dialect— sqlglot dialect name (default:snowflake)
Dialect support
The dialect parameter defaults to "snowflake" and accepts any sqlglot dialect string, for
example "bigquery", "spark", "duckdb", "postgres". Output expressions are rendered in
the specified dialect.
Development
Run tests:
uv run pytest
Run one test file:
uv run pytest tests/test_diff_engine.py
Lint:
uv run ruff check .
uv run ruff format --check .
See CONTRIBUTING.md for contribution guidelines.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file semantic_risk_engine-0.1.0.tar.gz.
File metadata
- Download URL: semantic_risk_engine-0.1.0.tar.gz
- Upload date:
- Size: 170.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f20e2987cdb06b6b71008f03dcf28cdd4aab87e8aa44fafcb37422558c2bb6a
|
|
| MD5 |
04286502133548ce9b3eafc9658f3489
|
|
| BLAKE2b-256 |
6a978fd8d7b6cf486a2ccccbe5e3d5b0383b26f19f4e2582851799ab9f97ca8a
|
Provenance
The following attestation bundles were made for semantic_risk_engine-0.1.0.tar.gz:
Publisher:
release.yml on badaadata/semantic-risk-engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
semantic_risk_engine-0.1.0.tar.gz -
Subject digest:
4f20e2987cdb06b6b71008f03dcf28cdd4aab87e8aa44fafcb37422558c2bb6a - Sigstore transparency entry: 2138039597
- Sigstore integration time:
-
Permalink:
badaadata/semantic-risk-engine@86f50ec69c8ec69d2194a8fb83cd95b1dfa89258 -
Branch / Tag:
refs/tags/v1 - Owner: https://github.com/badaadata
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@86f50ec69c8ec69d2194a8fb83cd95b1dfa89258 -
Trigger Event:
push
-
Statement type:
File details
Details for the file semantic_risk_engine-0.1.0-py3-none-any.whl.
File metadata
- Download URL: semantic_risk_engine-0.1.0-py3-none-any.whl
- Upload date:
- Size: 144.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ccdc36ed3b00cab844c36ca808dab6694ea78a082b438f2ec7d280e0e88de32
|
|
| MD5 |
53d4eb9563170bdd0f75518ec100cc75
|
|
| BLAKE2b-256 |
ebc21497ac3d50c89e581a0492e4311bc48e84147d871205a23f5f98b394c259
|
Provenance
The following attestation bundles were made for semantic_risk_engine-0.1.0-py3-none-any.whl:
Publisher:
release.yml on badaadata/semantic-risk-engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
semantic_risk_engine-0.1.0-py3-none-any.whl -
Subject digest:
2ccdc36ed3b00cab844c36ca808dab6694ea78a082b438f2ec7d280e0e88de32 - Sigstore transparency entry: 2138039610
- Sigstore integration time:
-
Permalink:
badaadata/semantic-risk-engine@86f50ec69c8ec69d2194a8fb83cd95b1dfa89258 -
Branch / Tag:
refs/tags/v1 - Owner: https://github.com/badaadata
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@86f50ec69c8ec69d2194a8fb83cd95b1dfa89258 -
Trigger Event:
push
-
Statement type: