Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/simonw/LLM/llms.txt

Use this file to discover all available pages before exploring further.

Every prompt you run with LLM is automatically saved — along with the model’s response, token counts, conversation ID, and any attachments or fragments — to a local SQLite database. This lets you search your history, resume conversations, audit costs, and export data for further analysis.

Log Database Location

llm logs path
On macOS this typically outputs:
/Users/simon/Library/Application Support/io.datasette.llm/logs.db
The path varies by operating system and follows the platformdirs convention.

Controlling Logging

CommandEffect
llm logs offDisable logging for all future prompts
llm logs onRe-enable logging
llm logs statusShow current status and database statistics
llm 'prompt' -n / --no-logSkip logging for a single prompt
llm 'prompt' --logForce logging for a single prompt (when logging is off)
llm logs status
Example output:
Logging is ON for all prompts
Found log database at /Users/simon/Library/Application Support/io.datasette.llm/logs.db
Number of conversations logged: 33
Number of responses logged:     48
Database file size:             19.96MB

Viewing Logs

llm logs
Returns the three most recent logged items in Markdown format. Use -n to change the count:
llm logs -n 10      # ten most recent
llm logs -n 0       # everything ever logged

Output Formats

FlagOutput
(default)Markdown with prompt and response
-r / --responseMost recent response only, as plain text
-x / --extractFirst fenced code block from selected entries
--xl / --extract-lastLast fenced code block
--jsonFull JSON array
-t / --truncateTruncate long prompts and responses
-u / --usageInclude token usage information

Short Mode

-s / --short prints a compact YAML summary with truncated prompts and no response text — useful for a quick overview:
llm logs -n 2 --short
Example output:
- model: deepseek-reasoner
  datetime: '2025-02-02T06:39:53'
  conversation: 01jk2pk05xq3d0vgk0202zrsg1
  prompt: H01 There are five huts. H02 The Scotsman lives in the purple hut...
- model: o3-mini
  datetime: '2025-02-02T19:03:05'
  conversation: 01jk40qkxetedzpf1zd8k9bgww
  system: Formatting re-enabled. Write a detailed README with extensive usage examples.
  prompt: <documents> <document index="1"> <source>./Cargo.toml</source>...
Add --usage to include token counts:
llm logs -n 1 --short --usage

Filtering Logs

By Conversation

View all logs for the most recent conversation:
llm logs -c
View logs for a specific conversation by ID:
llm logs --cid 01h82n0q9crqtnzmf13gkyxawg

By Search Term

Full-text search across prompts and responses (most relevant first):
llm logs -q 'cheesecake'
Sort by recency instead, and limit results:
llm logs -q 'cheesecake' -l -n 3

By Model

Filter to logs for a specific model or alias:
llm logs -m chatgpt
llm logs -m gpt-4o

Past a Specific ID

Retrieve every log recorded after a known response ID (useful for incremental processing):
llm logs --id-gt 01jm8ec74wxsdatyn5pq1fp0s5
llm logs --id-gte 01jm8ec74wxsdatyn5pq1fp0s5   # inclusive
IDs are issued in ascending time order, so this returns everything since that record.

By Fragment

Filter for logs that used a specific fragment (accepts hash, alias, URL, or file path):
llm logs -f https://llm.datasette.io/robots.txt --expand
Multiple -f options return only responses that used all of the specified fragments.

By Tool

Filter for responses that involved a result from a specific tool:
llm logs -T simple_eval
Show all responses that involved any tool result (including from --functions):
llm logs --tools

By Schema

Filter responses that used a specific schema (any format accepted by --schema):
llm logs --schema 'name, age int, bio'
Combine with --data, --data-array, and --data-key to extract the raw JSON. See the schemas documentation for details.

Browsing Logs with Datasette

Datasette provides a browser-based SQL interface over the logs database:
datasette "$(llm logs path)"
This opens an interactive web UI at http://localhost:8001 where you can run SQL queries, explore tables, and export data.

Backing Up Your Database

llm logs backup /tmp/backup.db
This uses SQLite’s VACUUM INTO to create a clean, compacted copy of the database.

SQL Schema

The logs.db database contains the following tables:
CREATE TABLE [conversations] (
  [id] TEXT PRIMARY KEY,
  [name] TEXT,
  [model] TEXT
);
CREATE TABLE [schemas] (
  [id] TEXT PRIMARY KEY,
  [content] TEXT
);
CREATE TABLE "responses" (
  [id] TEXT PRIMARY KEY,
  [model] TEXT,
  [prompt] TEXT,
  [system] TEXT,
  [prompt_json] TEXT,
  [options_json] TEXT,
  [response] TEXT,
  [response_json] TEXT,
  [conversation_id] TEXT REFERENCES [conversations]([id]),
  [duration_ms] INTEGER,
  [datetime_utc] TEXT,
  [input_tokens] INTEGER,
  [output_tokens] INTEGER,
  [token_details] TEXT,
  [schema_id] TEXT REFERENCES [schemas]([id]),
  [resolved_model] TEXT,
  [reasoning] TEXT
);
CREATE VIRTUAL TABLE [responses_fts] USING FTS5 (
  [prompt],
  [response],
  content=[responses]
);
CREATE TABLE [attachments] (
  [id] TEXT PRIMARY KEY,
  [type] TEXT,
  [path] TEXT,
  [url] TEXT,
  [content] BLOB
);
CREATE TABLE [prompt_attachments] (
  [response_id] TEXT REFERENCES [responses]([id]),
  [attachment_id] TEXT REFERENCES [attachments]([id]),
  [order] INTEGER,
  PRIMARY KEY ([response_id], [attachment_id])
);
CREATE TABLE [fragments] (
  [id] INTEGER PRIMARY KEY,
  [hash] TEXT,
  [content] TEXT,
  [datetime_utc] TEXT,
  [source] TEXT
);
CREATE TABLE [fragment_aliases] (
  [alias] TEXT PRIMARY KEY,
  [fragment_id] INTEGER REFERENCES [fragments]([id])
);
CREATE TABLE "prompt_fragments" (
  [response_id] TEXT REFERENCES [responses]([id]),
  [fragment_id] INTEGER REFERENCES [fragments]([id]),
  [order] INTEGER,
  PRIMARY KEY ([response_id], [fragment_id], [order])
);
CREATE TABLE "system_fragments" (
  [response_id] TEXT REFERENCES [responses]([id]),
  [fragment_id] INTEGER REFERENCES [fragments]([id]),
  [order] INTEGER,
  PRIMARY KEY ([response_id], [fragment_id], [order])
);
CREATE TABLE [tools] (
  [id] INTEGER PRIMARY KEY,
  [hash] TEXT,
  [name] TEXT,
  [description] TEXT,
  [input_schema] TEXT,
  [plugin] TEXT
);
CREATE TABLE [tool_responses] (
  [tool_id] INTEGER REFERENCES [tools]([id]),
  [response_id] TEXT REFERENCES [responses]([id]),
  PRIMARY KEY ([tool_id], [response_id])
);
CREATE TABLE [tool_calls] (
  [id] INTEGER PRIMARY KEY,
  [response_id] TEXT REFERENCES [responses]([id]),
  [tool_id] INTEGER REFERENCES [tools]([id]),
  [name] TEXT,
  [arguments] TEXT,
  [tool_call_id] TEXT
);
CREATE TABLE "tool_results" (
  [id] INTEGER PRIMARY KEY,
  [response_id] TEXT REFERENCES [responses]([id]),
  [tool_id] INTEGER REFERENCES [tools]([id]),
  [name] TEXT,
  [output] TEXT,
  [tool_call_id] TEXT,
  [instance_id] INTEGER REFERENCES [tool_instances]([id]),
  [exception] TEXT
);
CREATE TABLE [tool_instances] (
  [id] INTEGER PRIMARY KEY,
  [plugin] TEXT,
  [name] TEXT,
  [arguments] TEXT
);

Key tables

TableDescription
conversationsOne row per conversation (id, name, model)
responsesEvery prompt/response pair, linked to a conversation
responses_ftsFull-text search index over prompt and response
fragmentsDeduplicated fragment content (hash, source, content)
fragment_aliasesNamed aliases pointing to fragment IDs
prompt_fragmentsJoin table: which fragments were used in which responses
system_fragmentsJoin table: system-prompt fragments per response
attachmentsBinary or URL-based attachments
schemasJSON schemas referenced by responses
toolsTool definitions used in prompts
tool_callsIndividual tool invocations by the model
tool_resultsOutputs returned by each tool call
responses_fts uses SQLite FTS5 for fast full-text search across prompts and responses.

Build docs developers (and LLMs) love