Skip to main content

Effortless Observability for LLM Prompts. Version, diff, replay, export, and guard costs with ease.

Project description

PromptScope 🧠🔍

Effortless Observability for LLM Prompts

Treat your prompts like code. Version, diff, replay, and debug them with ease.

PyPI version License: MIT GitHub issues GitHub stars


🤔 The Problem

In most LLM-powered apps today:

  • Prompts are unversioned strings scattered across the codebase.
  • Small changes can silently break behavior in unexpected ways.
  • No one knows why an output suddenly changed.
  • Reproducing bugs is a painful, manual process.
  • Upgrading to a new model is risky and hard to validate.

PromptScope fixes this. It brings the principles of Git-like version control and observability to your LLM prompts, so you can build more reliable and predictable AI applications.


✨ Key Features

  • ** automático Automatic Versioning:** Every change to a prompt's content, model, or parameters creates a new, immutable version. No manual tracking required.
  • 🔍 Intelligent Diffing: See exactly what changed between any two versions of a prompt, from a single word to a temperature setting.
  • 🛡️ Budget Guards: Optional max_cost thresholds prevent runaway responses and surprise bills.
  • 📦 One-Command Export: Dump every tracked prompt/version to portable JSON for backup or migration.
  • ⏳ Time-Travel Replay: Re-run any historical prompt version to reproduce outputs, debug issues, or compare model performance. (Coming Soon)
  • 📈 Performance Tracking: Monitor cost, latency, and quality metrics for each prompt over time. (Coming Soon)
  • 🚨 Drift Detection: Get alerted when prompt outputs change unexpectedly or degrade in quality. (Coming Soon)
  • 🔌 Seamless Integration: Works with popular libraries like OpenAI, with more integrations planned.

🚀 Quick Start

Get up and running with PromptScope in less than a minute.

1. Install PromptScope:

pip install promptscope

2. Set up your OpenAI API key:

export OPENAI_API_KEY="your-api-key"

3. Use the PromptScopeOpenAI client in your code:

It's a drop-in replacement for the standard openai.OpenAI client, but with added powers.

# your_app.py
from promptscope.openai import PromptScopeOpenAI

# Use it just like the regular OpenAI client
# Caching and retries are enabled by default!
# Optional: set max_cost (USD) to guard against expensive responses
client = PromptScopeOpenAI(retries=3, max_cost=0.01)

def generate_summary(text: str):
    # This prompt will be automatically tracked by PromptScope
    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "system", "content": "You are a helpful assistant that summarizes text."},
            {"role": "user", "content": f"Please summarize the following text:\n\n{text}"}
        ],
        # Track this prompt under the name "text_summarizer"
        # This is a custom parameter for PromptScope
        extra_body={"prompt_name": "text_summarizer"}
    )
    return response.choices[0].message.content

# Your prompt and its response are now saved and versioned in PromptScope!
summary = generate_summary("LLMs are transforming the way we build software...")
print(summary)

4. Explore your prompt history with the CLI:

Now you can use the promptscope CLI to inspect what happened — and even export everything.

# List all tracked prompts
promptscope list

# Show the history of your summarizer prompt
promptscope show text_summarizer

# Diff the latest version with the previous one
promptscope diff text_summarizer --from-version previous --to-version latest

# Export all prompts/versions to JSON
promptscope export --pretty --out promptscope_export.json

⚙️ Installation

You can install PromptScope using pip:

pip install promptscope

Database Configuration

By default, PromptScope uses a local SQLite database (promptscope.db) in your current working directory.

To specify a different path, set the PROMPTSCOPE_DB environment variable:

export PROMPTSCOPE_DB=/path/to/your/promptscope.db

📚 Usage

Python Library

The PromptScopeOpenAI and PromptScopeAsyncOpenAI clients are the easiest way to integrate PromptScope into your application. They are drop-in replacements for the standard OpenAI clients and automatically handle prompt tracking, versioning, caching, and retries.

To track a prompt, pass an extra_body with a prompt_name to the create method:

from promptscope.openai import PromptScopeOpenAI

client = PromptScopeOpenAI()

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[...],
    extra_body={"prompt_name": "my_awesome_prompt"}
)

Any changes to the model, messages, or other parameters will create a new version of my_awesome_prompt.

Optional: add a budget guard

You can cap per-request cost to prevent runaway responses. Set max_cost (USD) when constructing the client; a BudgetExceededError is raised if the model response would exceed it.

from promptscope.openai import PromptScopeOpenAI, BudgetExceededError

client = PromptScopeOpenAI(max_cost=0.02)  # cap each call at ~$0.02

try:
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[...],
        extra_body={"prompt_name": "guarded_prompt"}
    )
except BudgetExceededError as exc:
    # Decide whether to retry with a cheaper model or alert the user
    print(f"Too expensive: {exc}")

CLI

The promptscope CLI is your command center for prompt observability.

  • promptscope list: List all tracked prompts.
  • promptscope show <prompt_name>: Show the history and versions of a prompt.
  • promptscope diff <prompt_name>: Diff two versions of a prompt.
  • promptscope replay <prompt_name>: Replay a past prompt version.
  • promptscope export: Export all prompts and versions to JSON (for backup or migration).

For detailed options, run promptscope --help.


🤝 Contributing

We love contributions from the community! Whether it's a bug report, a new feature, or an improvement to the documentation, we welcome your help.

Please see our CONTRIBUTING.md for detailed instructions on how to get started.


💬 Community

  • GitHub Issues: Have a bug or feature request? Open an issue.
  • Discord: Join our community on Discord for help, discussion, and to share your projects. (Link coming soon!)

PromptScope is an open-source project created by PromptScope Dev.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

promptscope-0.1.1.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

promptscope-0.1.1-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

Details for the file promptscope-0.1.1.tar.gz.

File metadata

  • Download URL: promptscope-0.1.1.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.1 Linux/6.8.0-1030-azure

File hashes

Hashes for promptscope-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c420b6984f9b46a40cf97e56935b2bd898fff921cadc4fe1d1f1e2ebf991c9d5
MD5 1d1c8aa5da4862de577fdcab76278911
BLAKE2b-256 11d4dd3ae9866dc477be79987cd8797c94f9721557ffe5a72c8222a12327f955

See more details on using hashes here.

File details

Details for the file promptscope-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: promptscope-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 43.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.1 Linux/6.8.0-1030-azure

File hashes

Hashes for promptscope-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9c806e76fdca3fe51850d13c4ec7903ec40f7812d611ba90d272655c88970be3
MD5 54996d285bc42b04fdbf2036a83b065b
BLAKE2b-256 cfef4f1f1085d5ecdc839f5022e54c0d69260507afa23992f60cfe8a30fbcf6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page