LiteCLI is a command-line client for SQLite databases that has auto-completion and syntax highlighting. I’ve added the ability to use an LLM to create a SQL query.

Disclaimer: This is an EXPERIMENTAL feature. Not yet released.

Ask a question about your database in English and get a SQL query back to find out the answer.

This is the SQLite db used by Chrome.

Exploring my Chrome history to find interesting things about my browsing habits.

Adjust the SQL before executing it. Sometimes the SQL returned by the LLM is close but not quite right. No problem we can edit the query with all the litecli features before executing it.

Edit the query before execution.

The explanation for the SQL query is provided to help understand the reasoning behind it. The explanation is useful for the LLMs themselves to produce higher quality answers.

Implementation Details

This feature uses the llm python library to interface with an LLM.

The final prompt sent to the LLM includes the schema for the database and an example row from each table in the database. The prompt is designed to craft a SQL query to answer your question.

The demo above uses GPT-4o model. But the model can be swapped out for a local LLM running in Ollama.

I learned a few things from this experiment.

  1. Chrome History stores the timestamps as microseconds since 1601-01-01.
  2. Both GPT-4o and Claude 3.5 Haiku recognized the Chrome history DB and crafted my SQL queries to adjust for this special start timestamp.
  3. Local LLMs (especially qwen2.5-coder) are good enough and fast enough to produce high quality results.

Inspiration

This feature is heavily inspired by Simon’s sqlite-utils-ask plugin. Thanks to Simon for creating the llm library that made it trivial to add this feature.

This feature currently lives in a git branch: https://github.com/dbcli/litecli/tree/ai