Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semantic_risk_engine-0.1.0.tar.gz (170.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

semantic_risk_engine-0.1.0-py3-none-any.whl (144.0 kB view details)

Uploaded Python 3

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

Hashes for semantic_risk_engine-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4f20e2987cdb06b6b71008f03dcf28cdd4aab87e8aa44fafcb37422558c2bb6a
MD5 04286502133548ce9b3eafc9658f3489
BLAKE2b-256 6a978fd8d7b6cf486a2ccccbe5e3d5b0383b26f19f4e2582851799ab9f97ca8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for semantic_risk_engine-0.1.0.tar.gz:

Publisher: release.yml on badaadata/semantic-risk-engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file semantic_risk_engine-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for semantic_risk_engine-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ccdc36ed3b00cab844c36ca808dab6694ea78a082b438f2ec7d280e0e88de32
MD5 53d4eb9563170bdd0f75518ec100cc75
BLAKE2b-256 ebc21497ac3d50c89e581a0492e4311bc48e84147d871205a23f5f98b394c259

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page