Record and replay LLM interactions
Project description
llm_recorder
llm_recorder is a basic observability and debugging tool for language model apps.
It stores interactions with LLMs in a local directory and provides a way to replay them.
It is particularly useful for debugging chained LLM calls.
With llm_recorder, you can:
- Save every request/response pair to a directory.
- Replay part of previously recorded interactions instead of making live LLM calls.
You can use it to:
- Inspect LLM responses and requests that lead to them
- Record an execution path that leads to a specific response and then replay it and see how the application behaves downstream
- Modify the recorded responses before replaying them
Installation
pip install llm_recorder
Getting Started
For a quick start use enable_replay_mode; it monkey patches litellm to record and replay responses.
llm_recorder records any calls to litellm.completion and their responses and stores them in the directory specified by store_path.
Specify replay_count to replay previously recorded interactions (by default no interactions are replayed).
Once the replayed interactions are exhausted, llm_recorder falls back to live LLM calls.
The store_path is cleaned up at the start of each run, but interactions from the previous run are read before that cleanup.
Basic Example
from llm_recorder import enable_replay_mode
import litellm
enable_replay_mode(store_path="saves")
print("After:", litellm.completion.__name__)
# Now just use litellm as usual:
response = litellm.completion(
model="openai/gpt-4o",
messages=[{ "content": "Hello, how are you?","role": "user"}]
)
Then have a look at the 'saves' directory to see the recorded interactions.
Chained Calls Example
See examples/chained_calls.py for an example of how to use llm_recorder to record and replay chained LLM calls.
I saved the first interaction in examples/saves/chained_calls/ and the example
replays it before making live calls.
Advanced Usage
For more fine-grained control instantiate and use the LiteLLMRecorder class directly. See examples/direct_recorder.py.
Limitations
- Direct support for SDKs (not through litellm) and the recording HTTP client is experimental.
- Only supports synchronous calls.
Contributing
Contributions are welcome! Please open issues or pull requests on GitHub.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_recorder-0.1.0.tar.gz.
File metadata
- Download URL: llm_recorder-0.1.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa09c018911a94a08ee365feedf3995cc61bf2a066a5ef0e7a737367679dc0c0
|
|
| MD5 |
6f512875d5540aefc096b4ee3f90e8cd
|
|
| BLAKE2b-256 |
f3ae8a9927d3cd12d793425cd788ff8dbdbcb4810ad44f54430e31d14488a955
|
File details
Details for the file llm_recorder-0.1.0-py3-none-any.whl.
File metadata
- Download URL: llm_recorder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ebe31349ce1aff4f4e036d0b75ecf8532c30c64058760f870947cd7105d4b61
|
|
| MD5 |
7770d2abcb561b7a6f0835fd1bca110c
|
|
| BLAKE2b-256 |
3ae3db958919ba296d538ea4b3895bf5e587d7b53cc6964a449c53442a8bfcec
|