predicate v1.0.0

Natural language to SQL

Translate plain-text questions into parameterized, tenant-isolated PostgreSQL queries via an intermediate JSON schema. The AI never touches raw SQL.

Install

git clone https://github.com/palmshed/predicate.git
cd predicate
cp .env.example .env
docker-compose up --build

Quick start

import requests

res = requests.post(
    "http://localhost:8000/api/v1/query/compile",
    headers={"X-Predicate-API-Key": "test_key_alpha"},
    json={"prompt": "Show me orders over $500 from active customers"}
)

data = res.json()
print(data["compiled_sql"])   # SELECT orders.id ...
print(data["parameters"])     # ['tenant_alpha', 500, 'active']
print(data["results"])        # [{...}, {...}]

What it does

Performance

The SQL compiler generates parameterized queries in 3.6 microseconds at median, scaling to 641k queries/sec across 4 CPU cores with zero lock contention.

API endpoints

POST /api/v1/query/compile    Translate NL to SQL and execute
POST /api/v1/export/async    Queue bulk CSV export (Celery)
GET  /api/v1/metrics         Per-tenant analytics
GET  /health                 Health check (db, redis, uptime)
GET  /ready                  Readiness probe
GET  /metrics                Prometheus metrics

Resources