IntentQL
Intent-driven, deterministic natural language to SQL for Postgres.
Instead of letting an LLM generate free-form SQL, the LLM extracts a lightweight QueryIntent, and IntentQL deterministically compiles it into parameterized SQL and executes it safely.
Install
pip install intentql
To use the OpenAI SDK adapter shown below:
pip install "intentql[openai]"
With optional few-shot memory (recommended for production):
pip install "intentql[memory]"
Install from source
git clone https://github.com/Certifore/intentql
cd intentql
pip install -e ".[dev]"
Quick Start
1. Generate your schema from the database
intentql init --db "postgresql://user:pass@host/db"
# → config/schema.yaml (tables, columns, types, PKs, links — all auto-detected)
2. Enrich with LLM-generated descriptions (optional, recommended)
export LLM_API_KEY=sk-... # works with any OpenAI-compatible provider
intentql describe --schema config/schema.yaml --db "postgresql://user:pass@host/db"
# → Adds table + column descriptions using sample data for context
3. Ask questions
from sqlalchemy import create_engine
from openai import OpenAI
from intentql.agent import QueryAgent
engine = create_engine("postgresql+psycopg2://user:pass@host/db")
agent = QueryAgent(
engine=engine,
schema_path="config/schema.yaml",
llm=OpenAI(api_key="sk-..."),
)
result = agent.ask("how many plumbing issues last year?")
print(result["rows"])
print(result["sql"])
Use Mistral instead of OpenAI
export MISTRAL_AI=...
# optional
export MISTRAL_MODEL=mistral-small-latest
agent = QueryAgent(
engine=engine,
schema_path="config/schema.yaml",
llm="mistral", # or "mistral:mistral-small-latest"
)
Use a local Ollama model
export OLLAMA_MODEL=intentql-gemma4
# optional
export OLLAMA_BASE_URL=http://127.0.0.1:11434
export OLLAMA_NUM_CTX=8192
agent = QueryAgent(
engine=engine,
schema_path="config/schema.yaml",
llm="ollama", # or "ollama:intentql-gemma4"
)
CLI Reference
| Command | Description |
|---|---|
intentql init --db URL |
Introspect Postgres and generate schema.yaml |
intentql describe --schema PATH --db URL |
Enrich schema with LLM-generated descriptions |
Run intentql --help for full options.
Documentation
Full documentation, benchmarks, and guides are at certifore.github.io/intentql_docs (source).
See ROADMAP.md for planned capabilities (lookup, trends, ratios, multi-step NL, and expressiveness goals).
Contributing
Contributions are welcome through pull requests. Please read CONTRIBUTING.md before submitting changes. The lead maintainer reviews and merges all changes into the official repository and is the only person who publishes official releases.
License
IntentQL is licensed under the Apache License 2.0.
Metadata
Release files for intentql 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| intentql-0.2.4.tar.gz | 151.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| intentql-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 310.0 kB
Release files / intentql-0.2.4.tar.gz
| Download URL | intentql-0.2.4.tar.gz |
|---|---|
| Size | 151.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94cf16a13bbdd75148e4ce589d29a75636a015a4c7c39fc17ccc4e18809b7ef8
|
|
BLAKE2b-256 checksum How to use checksums |
841417e0e9e47fd0494aec661315d28015295cf1420b8c7a4bc771922d7b27b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / intentql-0.2.4-py3-none-any.whl
| Download URL | intentql-0.2.4-py3-none-any.whl |
|---|---|
| Size | 158.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c5812d88d6fb6b144b06393eed5214d58804f89cc9b7ca2d236a8b5880bb67f2
|
|
BLAKE2b-256 checksum How to use checksums |
7b89f4909ba17833c6a162b778b6e5ebf85e23c98fa6a10f7eaf5f8327e73cb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|