Skip to main content

prompt-logger

Prompt Logger reliably captures all the AI prompts you execute so you can focus on experimentation with very minimal instrumentation code.

Features

  • Programmatically log AI/chatbot interactions (prompts and responses) to a SQLite database
  • Command-line interface to export logs to JSONL format
  • Support for multiple user-defined namespaces
  • Decorator for easy integration with existing code

Installation

pip install prompt-logger

Usage

Working with OpenAI-style clients

If you're using the OpenAI client or a client that satisfies the chat.completions.create interface you can attach Prompt Logger to the client and it will automatically record all your prompts and their generated completions.

from prompt_logger import PromptLogger
from openai import OpenAI

# Create the logger with a namespace and a database
logger = PromptLogger(namespace="my-namespace", database="sqlite:///my_prompts.db")

# Attach the logger to an AI client
client = OpenAI()
logger.attach_to_client(client)

# All completion requests to the client are logged
response = client.chat.completions.create(
   model="gpt-4.1",
   messages=[
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is the weather today?"}
   ],
   max_tokens=50
)

# Export used models as a JSONL file
logger.export_models("models.jsonl")

# Export chat prompts to a JSONL file
logger.export_chat_prompts("prompts.jsonl")

Exported models contain some metadata about models used in completion requests.

{"id": "74f0b720-dc78-491d-a123-2c33de50d2ee", "namespace": "my-namespace", "name": "gpt-4.1", "provider": "system", "created": 1744316542.0}

Exported prompts capture parameters used for completion requests and the generated completions.

{"id": "d215d38f-ec59-4d20-9493-1c7f4e9a977f", "namespace": "default", "model": "gpt-4.1", "messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the weather today?"}], "generation_kwargs": {"max_tokens": 50}, "completions": [{"role": "assistant", "content": "I don't have access to real-time data or current weather updates. For today's weather, you can:\n\n- Check your preferred weather app (such as The Weather Channel, AccuWeather, or your phone's built-in weather app)\n- Search \"weather", "finish_reason": "length"}], "inference_on": 1745360143.533253, "inference_seconds": 1.272673}

Working with custom code

You can use the save_interaction function to log one-off prompts.

from prompt_logger import PromptLogger, capture

# Initialize the logger
logger = PromptLogger("my-namespace", database="sqlite:///my_prompts.db")

# Log a single prompt and response
logger.save_interaction("What is the weather?", "It's sunny!")

# Export to JSONL
logger.export_text_prompts("prompts.jsonl")

Or use the capture decorator to log prompts more automatically.

# Use the decorator to automatically log prompts
@capture(namespace="my-namespace", database="sqlite:///my_prompts.db")
def generate_text(prompt):
    # Your LLM call here
    return "Generated response"

Using the command line tool

You can use the command line tool to export models and prompts previously logged to the database.

$ prompt-logger export models models.jsonl --namespace=my-namespace --database=sqlite:///my_prompts.db
$ prompt-logger export prompts prompts.jsonl --namespace=my-namespace --database=sqlite:///my_prompts.db

Development

  1. Clone the repository
  2. Install development dependencies:
    pip install -e ".[dev]"
    
  3. Run tests:
    pytest
    

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Metadata

Release files for prompt-logger 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prompt-logger 0.2.0
File Size Uploaded
prompt-logger-0.2.0.tar.gz 24.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prompt-logger 0.2.0
File Interpreter ABI Platform
prompt_logger-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 49.1 kB

Release files / prompt-logger-0.2.0.tar.gz

Download URL prompt-logger-0.2.0.tar.gz
Size 24.2 kB
Tags Source
SHA-256 checksum
How to use checksums
82c1892ec0975a17b0e41be84ed79158a50e5b2dfd6be2b82286742fd66acb46
BLAKE2b-256 checksum
How to use checksums
9cb51594bbb09664abfa0b44cfd3f257702ea19c58378940e71efe8325747d5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 25, 2025.

Transparency log

Release files / prompt_logger-0.2.0-py3-none-any.whl

Download URL prompt_logger-0.2.0-py3-none-any.whl
Size 24.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3fff63175ce44a13b5fac326b7cba2fc2bcbfd085674dffca7b25798d234f029
BLAKE2b-256 checksum
How to use checksums
02ef10db13e032609772c274ad2e9a69321e57d38d247017ae1e007c4394a804
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 25, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page