All writing
AI Experiment·January 20, 2026·10 min read

Metadata-Driven Text-to-SQL That Doesn't Lie

How FinOps Hub keeps natural-language SQL trustworthy: route to template SQL when a metadata route exists, fall back to LLM SQL when it doesn't, then validate, retry, and cache.

AIDatatext-to-sqlazure-openaidatabricks

The failure mode

Ask one LLM call to write SQL across several schemas and it will confidently invent joins. A better prompt doesn't fix it. Structure does: route to deterministic template SQL where a metadata route exists, fall back to LLM SQL only where it must, then validate and auto-correct.

Guardrails that hold

The SQL is read-only: no DML or DDL, no SELECT *, no multi-statements, no raw-layer scans, and always a row limit. A full-response cache keyed on the question makes answers identical and instant, and every answer shows the SQL it ran.

Referenced architecture
FinOps Hub — Hybrid SQL Engine

The staged pipeline behind FinOps Hub: route, plan, generate SQL (template or LLM), validate, execute, and summarize, with guardrails and a deterministic cache.