DistillQL

Use any LLM

distillql ask answers a question with any model that speaks OpenAI's chat-completions API with tool calling. DistillQL runs the conversation itself: it sends the question and four tools to the model, runs each tool call, sends the result back, and prints the answer with the query behind it. No AI app and no MCP extra are needed.

pip install distillql
distillql ask distillql.yaml "net revenue from paid orders last month" --model gpt-oss:20b

With no address given, it asks Ollama on this machine (http://localhost:11434/v1).

Models on this machine

Runs the model Address Example model
Ollama http://localhost:11434/v1 gpt-oss:20b, gemma4:31b, qwen3.5:27b
LM Studio http://localhost:1234/v1 the model's key in LM Studio
llama.cpp server, vLLM the address it prints, ending in /v1 the model it serves

An agent loop needs a long context window: set at least 32k tokens in Ollama (the app's slider, or OLLAMA_CONTEXT_LENGTH) or LM Studio (lms load <model> -c 32768). A short window cuts tool results and the model repeats itself.

Models elsewhere

A cloud model needs its address in the config, because the question and the tool results leave the machine:

llm:
  base_url: https://api.openai.com/v1
  model: your-model-name
  api_key_env: OPENAI_API_KEY        # the variable that holds the key; never the key itself
  allow_hosts: [api.openai.com]
Provider base_url
OpenAI https://api.openai.com/v1
Google Gemini https://generativelanguage.googleapis.com/v1beta/openai
Anthropic https://api.anthropic.com/v1
Mistral https://api.mistral.ai/v1
OpenRouter https://openrouter.ai/api/v1

Before the first request to such an address, ask prints the host and what it will send.

What the model may see

These limits hold in code. Only the config's llm: section can loosen them; no flag can.

  • This machine only, by default. Any other address must be in llm.allow_hosts and use https. Redirects are never followed, and proxies set in the environment are not used.
  • Keys from the environment only. llm.api_key_env names the variable. A key typed into the config stops the run.
  • Read-only. The model gets glossary, search_context, query and profile (describe and head). There is no write tool. Query limits and access policies apply as for any agent.
  • Few rows. A tool result shows at most llm.max_rows rows (default 20). With llm.send_rows: false the model sees column names and counts only, and DistillQL prints the final query's rows to you.
  • Personal columns held back. A column whose name reads as personal (email, phone, address, birth date, national id, card number and the like), or that the crawl tagged as personal from its values, never has its values sent, nor any value computed from it other than a count. Name more in llm.never_send; let one through the name check and the crawl's tag with llm.send_columns. Text that looks like an email address, a card number or a US social security number is masked in everything sent.
  • Database text is data. Comments and values stay fenced in « », and the model is told never to follow them.
  • Bounded. At most llm.max_turns replies (15), llm.max_tool_calls tool calls (30) and llm.timeout_seconds (300) a question.
  • Logged. Each request goes to .distillql/ask-log.jsonl beside the config: time, host, model, bytes sent, tools called and SQL run. No rows and no key.

A model can still learn about a held-back column through counts it asks for, such as how many emails end in one domain. For data that must not leave, keep the model on this machine, and let the database's own grants decide what the user can read.

From Python

import distillql

answer = distillql.ask("distillql.yaml", "net revenue from paid orders last month", model="gpt-oss:20b")
print(answer.text)
print(answer.sql)
print(answer.rows)        # the first rows of the last query, read here; never sent anywhere

answer.explain holds the explain record of that query, and answer.stopped says why a run ended early.