Skip to main content

ostrict

CI

A strict CI linter for semantic views, and a deterministic, FinOps-safe semantic compiler + MCP server for AI data agents.

Ostrict = OSI + strict. Unlike the myth, Ostrict never buries its head in the sand when AI hallucinates SQL.

Most data warehouses have no native, strictly-enforced semantic views. When text-to-SQL agents query them through loose YAML or flexible graph layers, the failure modes are always the same: non-deterministic SQL, fan-out double counting, ambiguous join paths, raw-row dumps, and runaway scan costs.

This project makes the semantic model a blueprint, never a materialization:

.sql DDL / .yaml spec ──parse──▶ canonical AST (Pydantic v2)
        ──lint (SV-R1..R10)──▶ valid blueprint
        ──compile(request)──▶ one deterministic SQL statement ──connector──▶ rows
  • Dual input, one AST. CREATE SEMANTIC VIEW DDL (human-authored) and a native YAML contract (automation-friendly) build byte-identical models.
  • Static ground rules (SV-R1..R10). Primary keys and grain comments, a directed many-to-one join DAG with exactly one path between any two tables, no numeric dimensions, no CURRENT_DATE, snapshot metrics declared NON ADDITIVE BY, globally unique field names and synonyms, a security deny-list, comment templates. ostrict lint blocks CI on ERRORs.
  • Deterministic compilation. Same request, same SQL, byte for byte. Joins only walk child→parent (zero fan-out, enforced); metrics of different grains drill across via UNION ALL; derived ratios divide NULL-safely; every expression is built as a sqlglot AST — no string concatenation anywhere.
  • FinOps guardrails. At least one metric per query (no raw dumps), partition filters required and pushed into each table's subquery (the only placement BigQuery honors on joined tables), LIMIT injected and capped, BigQuery dry-run byte ceiling.
  • MCP server (mcp ≥ 2). Five tools: list_semantic_views, inspect_semantic_view, get_dimension_values, compile_semantic_query, execute_semantic_query. The agent picks names from the catalog and never writes SQL; every refusal carries an error code and a repair hint.
  • Golden Questions eval. ostrict eval cases.yaml grades answer/refuse/clarify cases against DuckDB deterministically — no LLM judge.
  • OSI interchange. ostrict export|import converts views to and from Open Semantic Interchange YAML/JSON losslessly — guardrails travel in a namespaced custom_extensions.strict_semantic block, and every import must pass the full SV-R1..R10 gate.
  • Open-core plugin hooks. on_model_loaded, before_compile (RBAC filter injection), after_compile (cache/lineage), on_query_executed (audit).

Quickstart

python -m venv .venv && .venv/bin/pip install -e '.[dev,mcp]'
.venv/bin/python -m pytest                                  # 80 tests
.venv/bin/ostrict lint tests/fixtures/ecommerce.sql
.venv/bin/ostrict eval tests/fixtures/golden_questions.yaml
.venv/bin/ostrict compile tests/fixtures/ecommerce.yaml \
    -m revenue -m aov -d region \
    -f '{"field":"order_date","op":">=","value":"2026-01-01"}' \
    -f '{"field":"order_date","op":"<","value":"2026-02-01"}' --dialect bigquery

Run the MCP server against the demo warehouse (in-memory DuckDB):

OSTRICT_CONFIG=$PWD/examples/config.duckdb.yml .venv/bin/ostrict-mcp

or register it with Claude Code:

claude mcp add ostrict -e OSTRICT_CONFIG=$PWD/examples/config.duckdb.yml -- $PWD/.venv/bin/ostrict-mcp

For BigQuery, copy examples/config.bigquery.example.yml, point views: at your private spec folder, and set max_bytes.

Writing a semantic view

The CREATE SEMANTIC VIEW DDL (.sql) and the native YAML (.yml) are equivalent; metadata the DDL has no slot for travels in structured comment directives (enforced by the linter as SV-R8.1 templates):

CREATE SEMANTIC VIEW ecommerce
  TABLES (
    orders AS shop.orders PRIMARY KEY (order_id)
      COMMENT = 'One row per order. Primary date: order_date. Partition: order_date BY order_date. Source: shop.orders.',
    customers AS shop.customers PRIMARY KEY (customer_id)
      COMMENT = 'One row per customer. Primary date: signup_date. Source: shop.customers.'
  )
  RELATIONSHIPS ( orders_customers AS orders (customer_id) REFERENCES customers (customer_id) )
  DIMENSIONS (
    customers.region AS region WITH SYNONYMS ('market') COMMENT = 'Customer home region. Values: EU, US, APAC.',
    orders.order_date AS order_date COMMENT = 'Date the order was placed. Grains: day, week, month.'
  )
  METRICS (
    orders.order_count AS COUNT(order_id) COMMENT = 'Number of orders placed. Population: all orders. Additivity: additive.'
  )
  COMMENT = 'Retail sales.'

Directives: One row per … (grain), Primary date: col., Point-in-time snapshot., Partition: col BY dimension (lookback Nd, lookahead Nd)., Grains: day, month., Type: timestamp., Values: a, b, c. See tests/fixtures/ecommerce.{sql,yaml} for the full twin fixtures.

Querying

{"metrics": ["revenue", "aov"], "dimensions": ["region", "order_date__month"],
 "filters": [{"field": "order_date", "op": "between", "value": ["2026-01-01", "2026-03-31"]},
             {"field": "aov", "op": ">", "value": 50}],
 "order_by": ["-revenue"], "limit": 100}

Time dimensions take a __grain suffix. Filters on dimensions apply before aggregation, filters on metrics after. Dimension-only queries are refused (ERR_METRIC_REQUIRED) — value discovery goes through get_dimension_values, a bounded SELECT DISTINCT … LIMIT ≤ 50.

OSI interchange

Exchange views with other semantic-layer tools as OSI (Open Semantic Interchange) documents:

ostrict export tests/fixtures/ecommerce.sql -o ecommerce.osi.yaml
ostrict export tests/fixtures/ecommerce.yaml --format json --strip-extensions
ostrict import ecommerce.osi.yaml -o views/imported.yaml

Exports are lossless: strict-semantic guardrails (dialect, partition pruning bounds, snapshot flags, time types) ride in custom_extensions.strict_semantic blocks, and an export → import round-trip rebuilds an equal AST. --strip-extensions emits vanilla OSI instead and warns on stderr for every guardrail that drops out. Imports are gated: the document is linted (SV-R1..R10) before it is written as a native spec, so external models cannot bypass the ground rules (--no-lint converts anyway, for inspection). The field-by-field mapping lives in docs/osi-mapping.md.

Layout

src/ostrict/
├── models/        # canonical AST, error codes, request/response contracts
├── parsers/       # CREATE SEMANTIC VIEW DDL (token-stream) + native YAML -> one builder
├── interchange/   # OSI (Open Semantic Interchange) export/import adapter
├── linter/        # SV-R1..R10 engine: structure / logic / governance rules
├── compiler/      # join-graph resolver, FinOps guardrails, sqlglot SQL builder
├── connectors/    # DuckDB, BigQuery (dry-run + byte cap), protocol
├── plugins/       # open-core lifecycle hooks
├── eval/          # Golden Questions runner (deterministic, no LLM)
└── mcp_server/    # the five MCP tools over stdio

Design departures from the original blueprint, with reasons, are in docs/REVISIONS.md.

Security & deployment responsibility

The server speaks stdio and is designed to run next to the agent, on your machine, with your credentials. If you expose it over a network (HTTP/SSE, a gateway, a shared host), authentication, transport security and tenant isolation are yours to provide — nothing here does that for you.

Expect defense in depth from the warehouse side too: run the connector with a least-privilege, read-only account scoped to the datasets the views name. The compiler never concatenates SQL strings — filter values become typed sqlglot literals, operators come from a fixed whitelist, and every identifier must resolve against the linted model — but the SQL that reaches your warehouse should still be gated by the warehouse's own permissions. Per the Apache 2.0 license, the software is provided as is, without warranty; securing the deployment is the deployer's responsibility.

Report vulnerabilities privately via GitHub Security Advisories, not public issues.

Contributing

Scope is deliberately strict and minimal — read CONTRIBUTING.md before proposing features. Short version: determinism is non-negotiable, escape hatches get declined, and extensions belong in plugins.

Renamed from strict-semantic-mcp

v0.3.0 renamed the project to ostrict. Old integrations keep working: import strict_semantic is a deprecated alias of ostrict (same module objects), the strict-semantic / strict-semantic-mcp entry points remain, and STRICT_SEMANTIC_CONFIG is honored when OSTRICT_CONFIG is unset. The OSI extension namespace stays custom_extensions.strict_semantic, so 0.2.x documents import unchanged. On PyPI, new releases ship as ostrict; strict-semantic-mcp stays at 0.2.0.

License

Apache 2.0 (see LICENSE and NOTICE). Fixtures and examples are a generic e-commerce schema; keep your company's semantic views in a private repository and point the server at them via OSTRICT_CONFIG.

Metadata

Release files for ostrict 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ostrict 0.3.0
File Size Uploaded Provenance Actions
ostrict-0.3.0.tar.gz 68.7 kB With provenance Details for ostrict-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ostrict 0.3.0
File Interpreter ABI Platform Actions
ostrict-0.3.0-py3-none-any.whl Python 3 none any Details for ostrict-0.3.0-py3-none-any.whl

Total release size: 130.9 kB

Release files / ostrict-0.3.0.tar.gz

Download URL ostrict-0.3.0.tar.gz
Size 68.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2f65c2b04344be1f35bdb29324fbd621ba252df3b0d74031cacba16453f25589
BLAKE2b-256 checksum
How to use checksums
4babdf77eaa1765a4544b697030bf22303078926ba97f2f0e0284c7d8b8bead0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / ostrict-0.3.0-py3-none-any.whl

Download URL ostrict-0.3.0-py3-none-any.whl
Size 62.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54179fe75e48076bab80062b82c3ddec1ee8c03277e816f5327a1a3d48f87b16
BLAKE2b-256 checksum
How to use checksums
55cb4b3843c50d425c0b1857de838ca76efac63afdeca0a35a3caa4ff2f14bf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for ostrict 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ostrict-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page