Architecture

v1.0.0

How the natural language to SQL pipeline works, and why it is safe by design.

Pipeline

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

Security model

Compiler design

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.

Adaptability

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.

Observability

Found something unexpected? Report an issue.