Tools: SQLite Query
The sqlite tool gives your LLM the ability to query SQLite databases directly. This is a powerful way to provide access to structured data, allowing the LLM to perform data analysis, answer questions from a knowledge base, or check the state of an application.
Configuration
The snippets below show only the tool definition. They assume you have an interlocutor with a valid prompt and model configuration. See Getting Started for a full header example.
To configure the tool, you must provide the path to the SQLite database file. The database schema is automatically introspected and provided to the LLM, so it knows what tables and columns are available.
tools:
- sqlite: ./products.db
name: db_query
limit: 10000
readonly: true
details: >
Contains the full product catalog and inventory levels. Use this to
answer questions about what is in stock.
extensions:
- ./lib/vector0
- ./lib/mathThe path can include environment variables (for example, $DATA_DIR/main.db), which Lectic expands.
Configuration parameters
sqlite: (Required) Path to the SQLite database file.name: A custom tool name.readonly: To set the database as read only.limit: Maximum size of the serialized response in bytes. Large results raise an error instead of flooding the model.details: Extra high‑level context for the model. String,file:, orexec:are accepted. See External Prompts.extensions: A list of SQLite extension libraries to load before queries.
Example conversation
Configuration:
tools:
- sqlite: ./chinook.db
name: chinookConversation:
Who are the top 5 artists by number of tracks?
:::Assistant
I will query the database to find out.
<tool-call with="chinook">
<arguments>
<query>
┆SELECT
┆ar.Name,
┆COUNT(t.TrackId) AS TrackCount
┆FROM Artists ar
┆JOIN Albums al ON ar.ArtistId = al.ArtistId
┆JOIN Tracks t ON al.AlbumId = t.AlbumId
┆GROUP BY ar.Name
┆ORDER BY TrackCount DESC
┆LIMIT 5;
</query>
</arguments>
<results>
<result type="text">
┆- Name: Iron Maiden
┆TrackCount: 213
┆- Name: Led Zeppelin
┆TrackCount: 114
┆- Name: Metallica
┆TrackCount: 112
┆- Name: U2
┆TrackCount: 110
┆- Name: Deep Purple
┆TrackCount: 92
</result>
</results>
</tool-call>
Based on the data, the top artists by track count are Iron Maiden, Led
Zeppelin, Metallica, U2, and Deep Purple.
:::Writes and transactions
Writes are allowed by default. Each tool call runs inside a transaction and is atomic. If any statement in the call fails, Lectic rolls back the entire call, so the database is unchanged.
Limits and large results
The limit parameter caps the size of the serialized YAML that Lectic returns. If a result exceeds the cap, the tool raises an error. Tighten your query (for example, add LIMIT or select fewer columns) to stay under the cap.
Extensions
You can load extensions by path before queries run. On macOS, note that the system SQLite build may restrict loading extensions. Consult the Bun SQLite extension documentation if you hit issues.