Skip to main content

IntentQL — Intent-driven, deterministic natural language to SQL for Postgres.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

intentql-0.2.4.tar.gz (151.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

intentql-0.2.4-py3-none-any.whl (158.2 kB view details)

Uploaded Python 3

File details

Details for the file intentql-0.2.4.tar.gz.

File metadata

  • Download URL: intentql-0.2.4.tar.gz
  • Upload date:
  • Size: 151.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for intentql-0.2.4.tar.gz
Algorithm Hash digest
SHA256 94cf16a13bbdd75148e4ce589d29a75636a015a4c7c39fc17ccc4e18809b7ef8
MD5 0db13c94f404fddfa1633b0ad7e4ba23
BLAKE2b-256 841417e0e9e47fd0494aec661315d28015295cf1420b8c7a4bc771922d7b27b3

See more details on using hashes here.

File details

Details for the file intentql-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: intentql-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 158.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for intentql-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c5812d88d6fb6b144b06393eed5214d58804f89cc9b7ca2d236a8b5880bb67f2
MD5 1c9197f1aba57b62b4543566a59b2ba0
BLAKE2b-256 7b89f4909ba17833c6a162b778b6e5ebf85e23c98fa6a10f7eaf5f8327e73cb2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page