How the natural language to SQL pipeline works, and why it is safe by design.
Every query follows a strict path that separates the AI layer from the database layer. The AI generates a structured JSON blueprint. The compiler translates that blueprint into parameterized SQL. The AI never sees or generates raw SQL.
User Text
-> LLM Provider (OpenAI / OpenRouter)
-> JSON Blueprint (Pydantic validated)
-> SQL Compiler (parameterized, tenant-isolated)
-> PostgreSQL Execution
-> Redis Cache
-> Cached Response
%s placeholders. No string interpolation.ALLOWED_SCHEMA defines which tables and columns can be queried.RELATIONSHIP_GRAPH defines allowed foreign key paths.ALLOWED_AGGREGATIONS controls permitted aggregate functions.predicate_reader cannot write, only INSERT into audit_logs.The SQL compiler is a pure function: JSON blueprint in, parameterized SQL out. No side effects, no shared state, no I/O. This makes it trivially testable and allows it to scale linearly across CPU cores.
Benchmarked at 3.6 microseconds median latency and 174k queries/sec on a single process, scaling to 641k queries/sec across 4 cores with 92% efficiency.
To use predicate with a different database schema, modify only two definitions in app/compiler/sql_builder.py:
The rest of the pipeline (caching, auth, rate limiting, exports) adapts automatically.
/metrics: compile duration by provider, cache hits, query failures, query efficiency score./health checks db + redis, /ready for readiness probes.Found something unexpected? Report an issue.