simonw / simonw/llm

prompts in python are not saved it the database

Open
#738 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
Python
Stars
12.5k
Forks
998
Avg merge
3d 13h
Merged PRs (30d)
10

Description

Hello!

So I was using llm to make requests using the python api, and it seems that the prompts used in the python api are not saved into the database.
For me it was the expected behavior, because the docs says "llm defaults to logging all prompts and responses to a SQLite database.", and nothing on the python API page nor the Logging to SQLite.
Is this intended and not documented, a bug, or am I missing something?

small reproducible test:
test.py:

import llm

model = llm.get_model("gpt-4o-mini")
response = model.prompt("Five surprising names for a pet pelican")
print(response.text())
  1. uv init && uv add llm
  2. uv run llm logs -n 1 -> output your last message
  3. uv run test.py -> print 5 names
  4. uv run llm logs -n 1 -> should print "Five surprising names for a pet pelican" and the answer, print the same as 2.

Image

Otherwise, thank you very much for your amazing work, it really helps me a lot!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducible test.py example and run the two uv run llm logs -n 1 commands around model.prompt(...) to confirm the difference between CLI and Python API logging. Trace the Python API logging path and SQLite persistence behavior. Done means the prompt and response from the Python API appear in llm logs, or the documentation clearly explains that they are intentionally excluded.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlite
Domain
api, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.