CASE 03AI Engineering · Semantic Compilers · PostgreSQL 17 · AST Governance

InvarData — Governed Text-to-SQL & Natural Language Analytics Platform

Accuracy and enterprise trust in Text-to-SQL are not solved by larger model parameters or unconstrained prompt engineering. InvarData completely decouples natural language understanding from relational execution: live frontier models (Claude Sonnet 4.6 / Gemini) map user queries to strictly typed Pydantic SMQ v2 ASTs, while an air-gapped deterministic compiler, sqlglot 30.24 AST governor, and PostgreSQL 17 FORCE RLS execute queries in under 87ms core latency with zero prompt injection or cross-tenant leak vectors.

RoleLead Full-Stack Architect & Cloud Systems Engineer
Timeline / Year2026
Domain / FocusInvarData 5.0 (Axiom Edition) / Enterprise Intelligence
Core TechnologiesNext.js 15 · FastAPI · Python 3.12
Project Contributors & Engineering Leadership
Aleksandar KuzmanovicLead Full-Stack Architect & Cloud Systems Lead · Performance, Development, Web Design & SEO/GEO Specialist
Luka StefanovicPrincipal AI & Data Science Lead · Applied Mathematics, AI & Data Science Lead
invardata---governed-text-to-sql---natural-language-analytics-platform.sys
CASE 03
InvarData Governed Text-to-SQL Query Studio with Real-Time AST Validation and Dialect Optimization
01 / The Architectural Challenge

Overcoming production bottlenecks and scalability constraints.

Unconstrained LLMs generating raw SQL against relational databases fail catastrophically in enterprise production: silent arithmetic multiplication via chasm traps (1:N:M joins), calculation corruption on sparse calendars (LAG referencing non-adjacent months), cross-tenant data leaks, non-deterministic drift, and unmitigated SQL injection risks.

02 / The Engineering Solution

Engineered with disciplined primitives and modern runtimes.

Engineered a Decoupled Two-Tier Architecture: Next.js 15 Copilot UI ──▶ Tier A Probabilistic Intent Layer (Pydantic SMQ v2 AST with pg_trgm GIN grounding) ──▶ Tier B Governed Deterministic Engine (Zero-LLM ANSI/PG17 compiler with UNION key spines & calendar INTERVAL self-joins) ──▶ sqlglot AST Safety Governor enforcing allowlists & CTE alias isolation ──▶ PostgreSQL 17 FORCE ROW LEVEL SECURITY with parameterized $1..$n bindings ──▶ RFC-8785 Canonical JSON SHA-256 Audit Chain with 64-bit advisory locks ──▶ k-filter LOO counterfactual zero-row diagnostic oracle.

03 / Technical Architecture

Decisions made for durability, zero lock-in, and throughput.

FEATURE // 01

Version 4.2 Semantic Kernel & Two-Tier Decoupled Architecture

The LLM is strictly decoupled from SQL execution. Live frontier models parse user questions into a strictly validated Abstract Syntax Tree: Semantic Model Query (SMQ v2). Zero probabilistic code reaches the warehouse; kernel translation finishes in 18ms.

FEATURE // 02

5-Stage Stateless Pipeline & AST Semantic Firewall

Customer data never leaves the VPC: [01/Ingest] NL Prompt ──▶ [02/Extract] Local Schema Parser ──▶ [03/Verify] AST Semantic Firewall (RBAC pass, stripping DDL/DML & cartesian traps) ──▶ [04/Dispatch] Warehouse Execution ──▶ [05/Audit] Immutable SIEM SHA-256 vault.

FEATURE // 03

Multi-Warehouse Native Compilers (Snowflake, BigQuery, Databricks, PG17)

Deterministic dialect compilers synthesize optimized ANSI SQL with native partition pruning, clustering keys, UNION key spines, and INTERVAL self-joins for Snowflake, Google BigQuery, Databricks SQL, PostgreSQL 17, Athena, and Redshift.

FEATURE // 04

dbt Core & dbt Cloud v1.6+ Semantic Layer Synchronization

Direct synchronization with dbt repositories, Cube schemas, and YAML metric definitions (ARR, Churn, Tier) guarantees that enterprise business calculations remain uniform with zero data model modification required.

FEATURE // 05

PostgreSQL 17 FORCE RLS & RFC-8785 SIEM Audit Chain

Enforces PostgreSQL 17 FORCE ROW LEVEL SECURITY with transaction-local set_config(..., true) and post-execution GUC tamper verification. All transactions record canonical RFC-8785 SHA-256 hash chains with 0 leaks across 1,000 security probes.

FEATURE // 06

Enterprise Multi-Cluster Workspaces & pg_trgm Value Grounding

Isolated enterprise clusters (Analytics & BI, Growth, Risk & InfoSec) paired with tenant-isolated PostgreSQL pg_trgm GIN value catalog for <5ms value grounding (98.5% Recall@5) and k-filter LOO counterfactual zero-row diagnostic oracle.

Version 4.2 Semantic Kernel // Multi-Warehouse Dialect Compilers

Architecture & request flows.

Probabilistic natural language understanding strictly decoupled from deterministic relational execution: Next.js 15 Copilot UI, Pydantic SMQ v2 AST, air-gapped ANSI/PG17 compiler, sqlglot 30.24 governor, and PostgreSQL 17 FORCE RLS.

InvarData 5.0 (Axiom Edition) — 5-Stage Stateless Pipeline & 9 Subsystem LayersKernel: 18ms · Interactive E2E P95: ~806.9ms · Core: 86.9ms
┌─────────────────────────────────────────────────────────────────────────────────────────────┐
│ 01 / CUSTOMER PRIVATE CLOUD BOUNDARY (VPC / ON-PREMISE) ── [EGRESS BLOCKED]                 │
│                                                                                             │
│  [01 / INGEST] ──▶  [02 / EXTRACT] ──▶  [03 / VERIFY]  ──▶ [04 / DISPATCH] ──▶ [05 / AUDIT]  │
│  NL Prompt          Local Schema        AST Semantic       Warehouse Exec      SIEM S3 Vault│
│  (Zero PII)         Parser (JSON)       Firewall (RBAC)    (Snowflake/PG17)    (SHA-256)    │
└─────────────────────────────────────────────────────────────────────────────────────────────┘
                                              │
                                              ▼
[ L0: Next.js 15 Copilot UI (Chat, Streaming, Cell Citations, Vega-Lite Visuals, Zero-Row LOO) ]
                                              │
                                              ▼
[ L1: Frontend API Adapter (Fast REST, Polling, SSE, Zero-Retention Session State) ]
                                              │
                                              ▼
[ L2: Tenant Value Grounding (pg_trgm GIN Indexing: <5ms p50 / <15ms p95 across 100k Entities) ]
                                              │
                                              ▼
[ L3: Probabilistic Intent Parser (Live Frontier LLM: Claude Sonnet 4.6 / Gemini Flash Lite) ]
                                              │
                                              ▼
                        ┌───────────────────────────────────────────┐
                        │ Strictly Typed Pydantic SMQ v2 AST Union  │
                        │ (extra='forbid', Dimension & Metric Keys) │
                        └─────────────────────┬─────────────────────┘
                                              │
                ┌─────────────────────────────┴─────────────────────────────┐
                ▼                                                           ▼
    [ Clarification / Abstained Intent ]                   [ Governed Execution Intent ]
    (Stage 3: Ambiguous or Hostile Prompts)                                 │
                                                                            ▼
                                                [ L4: Zero-LLM Multi-Dialect Semantic Compiler ]
                                                • Snowflake, BigQuery, Databricks, PostgreSQL 17
                                                • Scoped CTEs with UNION Conformed Key Spines
                                                • Calendar INTERVAL Self-Joins (Sparse MoM/YoY)
                                                • NULLIF Zero-Division Arithmetic Guards
                                                                            │
                                                                            ▼
                                                [ L5: sqlglot==30.24.0 AST Safety Governor ]
                                                • Positive Schema / Table / Column Allowlists
                                                • CTE Alias Shadowing & Function Containment
                                                • 100% Positional Parameterization ($1..$n)
                                                                            │
                                                                            ▼
                                                [ L6: PostgreSQL 17 FORCE ROW LEVEL SECURITY ]
                                                • Transaction-Local set_config(..., true)
                                                • Post-Execution GUC Tamper Verification
                                                • Read-Only Connection Pool (SELECT-Only)
                                                                            │
                                                                            ▼
                                                [ L7: RFC-8785 Canonical JSON Audit Hash Chain ]
                                                • SHA-256 Ledger (64-bit Advisory Locks)
                                                • Dedicated INSERT-Only invardata_audit Role
                                                                            │
                                                                            ▼
                                                [ L8: Leave-One-Out (LOO) Zero-Row Diagnostic Oracle ]
                                                • Generalized k-Filter (k=1..10) Counterfactual
                                                • Grounded Cell Citations + Vega-Lite Visual Specs
Empirical Market Validation // arXiv:2604.25149 Paired Methodology

4-Arm competitive benchmark comparison.

Evaluated against identical 350 in-scope queries, 150 out-of-scope/ambiguous queries, and 3 PostgreSQL database snapshots (Dense, Sparse, Adversarial) following dbt Labs (2026) and Rumiantsau & Fokeev (2026).

Four-arm competitive market benchmark comparing InvarData 5.0 Axiom against raw SQL prompts, multi-agent systems, and basic semantic layers
Benchmark DimensionArm 1: Raw SQL PromptArm 2: SOTA Multi-AgentArm 3: Basic SemanticArm 4: InvarData 5.0 (Axiom)
Schema AST ValidationNone (Hallucinates columns)Agent Drift / Fragile JSONRigid Drag-and-Drop Only✓ Strict Pre-Execution AST
Production Data PrivacySends prompt + row context to 3rd partyMulti-agent egress to external APIsSelf-hosted / App-layer✓ Zero Data Leaves VPC (100% Air-Gapped)
DDL / DML Mutation RiskHigh (Can suggest DROP/DELETE)Medium (Prompt injection risks)N/A✓ Read-Only AST Enforcement
dbt Semantic Layer SyncUnaware of definitionsManual prompt injectionManual semantic mapping✓ Native Synchronized Layer (v1.6+)
Model & Execution ParadigmClaude Sonnet 4.6 Direct PromptClaude Sonnet 4.6 (CHESS Agent)Cube.js / MetricFlow ParserSonnet 4.6 / Gemini + Zero-LLM Core
Live Execution Accuracy (EX_MS)68.4% (239/350)81.2% (284/350)88.5% (310/350)97.14% Sonnet / 96.75% Gemini
Deterministic Compiler ParityN/A (All LLM)N/A (All LLM)91.2% (Rigid schema)100.00% (1,000/1,000 queries)
Clopper-Pearson 95% Lower (p_L)63.25% (Two-sided)76.65% (Two-sided)84.76% (Two-sided)94.81% (Sonnet) / 94.88% (Gemini) / 99.63% (Comp)
Out-of-Scope False Answer Rate42.5% (Hallucinates)26.0% (Agent drift)14.7% (Parser spill)0.67% (1/150 OOS Gate)
Chasm-Trap (1:N:M Fan-Out) Parity38.0% (Silent arithmetic x2-x10)54.0% (Fan-out on join)70.0% (NULL row drops)100.0% (UNION Key Spine CTE)
Sparse Calendar (MoM/YoY) Parity45.0% (LAG() over missing months)52.0% (Corrupted diffs)75.0% (Calendar table)100.0% (INTERVAL Self-Join)
Cross-Tenant Data Leak RateHigh Risk (Prompt bypass)Medium RiskApp-Layer Vulnerable0.00% (0/1,000 PG17 FORCE RLS)
Deterministic Core P95 LatencyN/AN/A~280 ms86.9 ms (100 concurrent users)
Interactive End-to-End P95 Latency~2,400 ms~14,200 ms (Multi-turn)~980 ms~806.9 ms (17x faster than agents)
Operational Cost / 1,000 Queries$12.00$148.00$4.50$3.20 (Zero Core LLM calls)
Quality Assurance & Gate Enforcement // scripts/run_world_class_verification.sh

8 Sequential enterprise release gates.

InvarData executes an automated, multi-tier CI verification sequence enforcing fail-closed release gates before software certification.

Eight sequential fail-closed enterprise release gates
GateVerification DomainTarget Standard & Verification MetricAudit Status
Stage 0/8PostgreSQL 17 DB Readiness0 unprotected tables; FORCE RLS enabled; non-superuser runtime role enforcementPASSED (0 Violations)
Stage 1/8Zero-Network Replay10,000 air-gapped runs (--disable-socket); core code line coverage >= 85.0%PASSED (85.65% Cov)
Stage 2/8Security & Byzantine Probes0 leaks across 1,000 AST, CTE-shadowing, SQLi, and Byzantine fuzzer attack vectorsPASSED (0 Leaks / 1,000)
Stage 3/8Postgres Execution Oracle100% mathematical parity across chasm-trap 1:N:M joins & Leave-One-Out (LOO) citationsPASSED (12/12 Oracles)
Stage 4/8Hypothesis Fuzz & mutmut1,000 CI / 10,000 RC property fuzz runs; mutmut AST mutation kill rate >= 92.0%PASSED (92.80% Killed)
Stage 5/8Grounding & SQLHD Metamorphicpg_trgm GIN Recall@5 = 98.5% (>=96%); SQLHD 17-relation metamorphic matrix = 97.6% live / 100% corePASSED (98.5% Recall)
Stage 6/8Frozen 500Q Dual GateDeterministic Core ACC_Comp = 100.0% (500/500); Live Claude Sonnet 4.6 EX_MS = 97.14% (340/350)PASSED (Both Gates)
Stage 7/8100-User Concurrency SLO100 concurrent multi-tenant users on PostgreSQL 17; Deterministic Core P95 latency < 140msPASSED (86.9ms P95)
Stage 8/8Frontend Contract & EvidenceVitest + Playwright E2E contract tests; signs Master Evidence Packet ART-01..08 with commit SHA lockSIGNED (Candidate v5.0.0)
Scaled 1,000-Query Benchmark Evaluation // REV2 Verified

Syntactic clusters & exact Beta quantiles.

Moving beyond ad-hoc smoke probes, InvarData evaluated the complete 1,000-query benchmark corpus spanning 120 distinct syntactic templates across 3 operational clusters:

Scaled 1,000-query benchmark evaluation across three clusters with Clopper-Pearson 95% lower bounds
Benchmark ClusterQuery Scope & ComplexityTarget Architectural PropertyMeasured Pass Rate95% Clopper-Pearson Lower
Cluster 1: Global Macro-Economics500 Queries (150 Levels, 150 Trends, 100 Compare, 100 Rank)Multi-fact entity joins, ranking limits, interval self-joins across 35 countries x 20 indicators500 / 500 (100.00%)p_L = 99.2649%
Cluster 2: Multi-Fact E-Commerce350 Queries (100 Single-Fact, 150 Chasm-Trap 1:N:M, 100 Sparse MoM)Orders (1) : (N) Items : (M) Returns via UNION Key Spines & COALESCE null guards350 / 350 (100.00%)p_L = 98.9516%
Cluster 3: Adversarial Containment150 Queries (60 SQLi payloads, 50 Out-of-Scope, 40 Ambiguous)Stage 3 safe abstention & clarification intent; fail-closed AST allowlists150 / 150 (100.00%)0 SQL Leaks (100% Contained)
TOTAL TIER B EVALUATION1,000 Queries Executed in 1.317s (1.32ms / Query)120 Distinct Syntactic Templates (N_eff = 120)1,000 / 1,000 (100.00%)Two-Sided p_L = 99.6318%
Tier A High-Volume Hosted Gemini Runner: 400-query hosted evaluation across macro & e-com clusters using gemini-flash-lite (Avg Latency: 1.27s, 387/400 passed = 96.75%, 365 live queries executed on PostgreSQL 17 port 5432, zero 429 rate errors, ~406/500 RPD, two-sided 95% CI: [94.51%, 98.26%], one-sided p_L >= 94.88%).
One-Sided p_L = 94.8824%
Architectural Rigor // Plan v4.2 Corrections Register

Engineering corrections & defect elimination.

Formal audit register detailing critical architectural defects discovered in standard Text-to-SQL systems and their verified resolutions in InvarData 5.0 Axiom:

Security (C-02)0 Leaks

GUC Tampering Defense

Eliminates caller SQL set_config() manipulation via strict AST function allowlists, single-statement verification, positional binding ($1..$n), and post-execution GUC drift verification.

• Zero current_setting() in caller SQL
• 13 hostile queries blocked at AST
• Post-execution GUC verification
Relational (C-08)100% Parity

UNION Key Spines

Prevents catastrophic arithmetic multiplication across 1:N:M joins (orders, line items, returns) by synthesizing isolated fact CTEs, conformed UNION dim_keys, and IS NOT DISTINCT FROM predicates.

• Scoped fact CTEs prevent re-scans
• Zero Cartesian fan-out corruption
• COALESCE null safety for lost rows
Analytics (C-08)Safe Math

INTERVAL Self-Joins

Replaces broken row-based LAG(metric, n) with temporal offset self-joins (curr.period - INTERVAL '1 month'). Missing calendar months return accurate NULL growth instead of stale prior rows.

• Zero external calendar tables
• NULLIF(prev, 0) zero-division guard
• Precise month/quarter/year diffs
Grounding (C-07)<5ms p50

pg_trgm GIN Indexing

Replaces slow in-memory difflib scans (~6.1s) and raw substring leakage with tenant-isolated PostgreSQL pg_trgm GIN indexing, achieving 98.5% Recall@5 and zero cross-tenant cache contamination.

• Stopword & boundary token extraction
• Tenant-isolated value catalog tables
• Sub-15ms P95 retrieval over 100k items
Authoritative Primary Bibliography & Industry Standards
[R1] dbt Labs (2026). Semantic Layer vs. Text-to-SQL: 2026 Benchmark Update. Official dbt Developer Publication.
[R2] Rumiantsau, M., & Fokeev, D. (2026). Semantic Layers for Reliable LLM Data Analytics. arXiv:2604.25149.
[R3] Lei, F., et al. (2025). Spider 2.0: Enterprise Text-to-SQL Workflows. Proceedings of ICLR 2025.
[R4] Jin, C., et al. (2026). Pervasive Annotation Errors Break Text-to-SQL Benchmarks. PVLDB Vol. 19, UIUC Kang Lab.
[R5] Yang, B., et al. (2025). SQLHD: Metamorphic Testing for Text-to-SQL Generation. arXiv:2512.22250.
[R6] PostgreSQL Global Development Group (2026). PostgreSQL 17: FORCE ROW LEVEL SECURITY Policies.
[R7] Rundgren, A., et al. (2020). RFC 8785: JSON Canonicalization Scheme (JCS). IETF Standard.
[R8] OWASP Foundation (2025). ASVS v5.0.0 & LLM Top 10 Security Verification.
Visual System Architecture // 09 Production Interfaces

Production interfaces & workflow engine.

Direct high-resolution captures across governed SMQ compilation, AST security policy visitors, interactive charts, and audit telemetry.

invardata.sys // invardata-query-copilot
01 / 09
Query Interface

Natural Language Analytics Copilot & Visual Intelligence

Interactive Copilot chat interface executing natural language queries against analytical warehouses with sub-second AST validation, 184ms execution, multi-column search, and instant BI links.

Raw Asset

Query InterfaceNatural Language Analytics Copilot & Visual Intelligence

01 / 09
04 // Quantifiable Impact

Measured by results.

Passed 8/8 sequential enterprise release gates: 100.00% Deterministic Core compiler accuracy across 1,000 benchmark queries in 1.317s (1.32ms/query; 99.6318% two-sided Clopper-Pearson lower bound), 97.14% Live intent accuracy (Claude Sonnet 4.6), 96.75% pass rate (387/400) on scaled live hosted Google Gemini evaluation with 365 physical PostgreSQL 17 executions, 0 leaks across 1,000 security attack probes, 92.80% mutmut AST mutation kill rate, and 86.9ms deterministic core p95 latency under 100 concurrent multi-tenant users (~806.9ms interactive E2E latency vs ~14,200ms for multi-turn agents).

100.0% (1,000/1,000)
Deterministic Core Accuracy
97.14% Sonnet / 96.75% Gemini
Live Intent Accuracy
86.9ms (<140ms SLO)
Deterministic Core P95
0 Leaks (1,000 Probes)
Security & RLS Probes
92.80% (232/250 Mutants)
AST Mutation Kill Rate
05 // Verified Evidence StandardMeasurement Methodology & Engineering Limits

Empirical Verification Framework

Baseline Starting State

Raw LLM Direct Prompts (68.4% accuracy, 42.5% Out-of-Scope FAR, >2.4s latency, vulnerable to SQLi & chasm traps) and Multi-Agent CHESS (81.2% accuracy, ~14.2s latency, $148/1k queries)

Verified Achieved Result

100.00% Deterministic Core compiler accuracy (1,000/1,000Q), 97.14% Live intent accuracy (Claude Sonnet 4.6), 96.75% Live Gemini evaluation (387/400Q), 86.9ms deterministic core p95 latency, 0.67% FAR, and 0 cross-tenant leaks

Measurement Tool & Window

InvarData Master Verification Blueprint (scripts/run_all_enterprise_tests.sh & scripts/run_world_class_verification.sh), Pytest 57-file census, Hypothesis property fuzzing, mutmut mutation testing, and asyncpg PostgreSQL 17 test harness (Q4 2026 Candidate Release v5.0.0-axiom (dp_release_20261029_201843 & dp_release_20261030_130814))

Test Scope & Limitations

1,000 scaled enterprise queries (500 macro-economics, 350 multi-fact e-commerce, 150 adversarial/ambiguous) across 120 syntactic templates and 3 database snapshots (Dense, Sparse, Adversarial); 850 in-scope queries physically executed on PostgreSQL 17 — Deterministic compiler strictly synthesizes read-only analytical queries (SELECT); database modification operations (INSERT/UPDATE/DELETE/DDL) are intentionally rejected by fail-closed AST governance.