LLM tools for running queries against SQLite
Install this plugin in the same environment as LLM.
llm install llm-tools-sqlite
To use this with the LLM command-line tool:
llm -T 'SQLite("content.db")' \
"Count rows in the most interesting looking table" --td
Or use llm chat
to chat with your database over multiple rounds:
llm chat -T 'SQLite("content.db")'
This tool currently only supports read-only queries. Attempts to write to the database will fail with an error.
With the LLM Python API:
import llm
from llm_tools_sqlite import SQLite
model = llm.get_model("gpt-4.1-mini")
result = model.chain(
"Show me the three most interesting looking tables",
tools=[SQLite("content.db")]
)
for s in result:
print(s, end="", flush=True)
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
cd llm-tools-sqlite
python -m venv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
llm install -e '.[test]'
To run the tests:
python -m pytest