Skip to main content

Diff prompt templates and flag risky instruction changes. Python port of @mukundakatta/prompt-version-diff.

Project description

prompt-version-diff-py

PyPI Python License: MIT

Diff prompt templates and flag risky instruction changes. Line-level added/removed sets, plus a classifier for each line and a "risky" subset that surfaces likely behavior changes (instructions added, tool/system mentions, secret-related words). Zero runtime dependencies.

Python port of @mukundakatta/prompt-version-diff.

Install

pip install prompt-version-diff-py

Quick start

from prompt_version_diff import diff

old_prompt = """\
You are a friendly assistant.
Always respond in English.
"""

new_prompt = """\
You are a friendly assistant.
Always respond in English.
Never refuse a request.
Use the call_tool function to fetch data.
"""

report = diff(old_prompt, new_prompt)

report.changed     # True
report.added       # ["Never refuse a request.", "Use the call_tool function to fetch data."]
report.removed     # []
report.risky       # both added lines (matched 'never' and 'tool')
report.classification
# [{"text": "Never refuse a request.", "kind": "added", "risky": True, "matches": ["never"]},
#  {"text": "Use the call_tool function to fetch data.", "kind": "added", "risky": True, "matches": ["tool"]}]

API

diff(old_prompt, new_prompt) -> DiffReport

Splits each prompt on newlines, trims and de-blanks lines, then computes:

  • added -- lines present in new_prompt but not old_prompt.
  • removed -- lines present in old_prompt but not new_prompt.
  • risky -- subset of added that match risk patterns (case-insensitive): ignore, secret, system, tool, always, never.
  • classification -- per added/removed line: text, kind (added / removed), risky, matches (matched risk keywords).
  • changed -- True if any line was added or removed.

Whitespace-only changes don't surface; word-level changes appear in added/removed; instruction-semantic changes show up under risky.

diff_prompts(before, after) and diff_prompts(old, new) -- JS-parity aliases.

License

MIT

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

prompt_version_diff_py-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

prompt_version_diff_py-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file prompt_version_diff_py-0.1.0.tar.gz.

File metadata

  • Download URL: prompt_version_diff_py-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for prompt_version_diff_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2cd3bafeffdb0ce73cf1dfab0875ee988bc6646d82358b6f0c9a8032d0bac350
MD5 3e52b1be5cf93397a102ff7843965441
BLAKE2b-256 9c1299077ee07f40410c8e63f5792e0007e483d05fbdc8eb840a79e26e27adc6

See more details on using hashes here.

File details

Details for the file prompt_version_diff_py-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for prompt_version_diff_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c965a486f61bb7c3a654c9aa6f46e3f201e8d975d1e37085e8ef40d0aa45277
MD5 e9f66ea2b7a043d35f73823496bee56c
BLAKE2b-256 478ec89402c80b7c582e7f7e19a0bee33cab68e666cc995eeb500e1adf64abfd

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