Skip to main content

promptsmith

Structured prompt builder and version manager for LLM engineers. Typed variables, Git-friendly versioning, human-readable diffs, A/B testing, and full audit trails. Works with any LLM. Zero dependencies.

PyPI version Python License: MIT


The Problem

Every LLM engineer ends up with prompts scattered across f-strings, Notion docs, and constants files. No versioning. No way to diff what changed. No audit trail of which prompt produced which output.

# the reality
prompt = f"Summarize this in {n} words: {text}"  # in utils.py
SYSTEM = "You are helpful..."                      # in constants.py  
prompt2 = "Summarize this concisely: " + text     # in api.py

promptsmith gives your prompts the same discipline as your code.


Installation

pip install promptsmith

No dependencies. Requires Python 3.8+.


Quick Start

from promptsmith import Prompt, PromptRegistry

# Define a typed prompt
prompt = Prompt(
    name="summarizer",
    template="Summarize this {content_type} in {max_words} words:\n\n{content}",
    variables={"content_type": str, "max_words": int, "content": str},
    description="General purpose summarizer",
)

# Render it — validates types before rendering
text = prompt.render(content_type="article", max_words=100, content="...")

# Save to registry
registry = PromptRegistry("./prompts")
registry.save(prompt)

# Load anywhere in your codebase
p = registry.load("summarizer")
text = p.render(content_type="email", max_words=50, content="...")

Core Concepts

Typed Variables

Variables are typed and validated before rendering — catch bugs before the LLM call:

prompt = Prompt(
    name="classifier",
    template="Classify this text as {label_a} or {label_b}:\n{text}",
    variables={
        "label_a": str,
        "label_b": str,
        "text": str,
    }
)

# Type errors caught early
prompt.render(label_a="positive", label_b="negative", text=42)
# PromptRenderError: Variable 'text' expected str, got int

Versioning

Every change creates a new version automatically:

p1 = registry.load("summarizer")  # 1.0.0

p2 = p1.update(
    template="Summarize this {content_type} concisely in under {max_words} words:\n\n{content}",
    changelog="Added 'concisely' — tighter outputs"
)
registry.save(p2)  # saves as 1.0.1

# Load specific version
old = registry.load("summarizer", version="1.0.0")
new = registry.load("summarizer", version="1.0.1")
new = registry.load("summarizer")  # latest

Human-Readable Diffs

print(registry.diff("summarizer", "1.0.0", "1.0.1"))
── Template ─────────────────────────────────────────
--- template (1.0.0)
+++ template (1.0.1)
@@ -1 +1 @@
-Summarize this {content_type} in {max_words} words:
+Summarize this {content_type} concisely in under {max_words} words:

── Metadata ─────────────────────────────────────────
  1.0.0 → 1.0.1
  changelog: Added 'concisely' — tighter outputs

A/B Testing

result = registry.ab_test(
    name="summarizer",
    version_a="1.0.0",
    version_b="1.0.1",
    inputs={"content_type": "article", "max_words": 100, "content": article_text},
    runner=lambda prompt: openai.chat.completions.create(
        model="gpt-4", messages=[{"role": "user", "content": prompt}]
    ).choices[0].message.content,
    scorer=lambda a, b: len(b) - len(a),  # positive = B wins
)

result.print_comparison()
print(f"Winner: {result.winner}")

Chat Models (System + User)

prompt = Prompt(
    name="assistant",
    template="Answer this question: {question}",
    system="You are a helpful assistant. Be concise.",
    variables={"question": str},
)

messages = prompt.render_messages(question="What is BPE tokenization?")
# [{"role": "system", "content": "You are..."}, {"role": "user", "content": "Answer..."}]

response = openai.chat.completions.create(model="gpt-4", messages=messages)

Version History & Audit Trail

# Full history
for entry in registry.history("summarizer"):
    print(f"v{entry['version']} — {entry['changelog']} ({entry['created_at'][:10]})")

# Past A/B results
for run in registry.ab_history("summarizer"):
    print(f"{run['version_a']} vs {run['version_b']} → winner: {run['winner']}")

Storage (Git-Friendly)

prompts/
├── promptsmith.db          ← SQLite index for fast queries
├── summarizer/
│   ├── 1.0.0.json          ← full prompt definition
│   └── 1.0.1.json
└── classifier/
    └── 1.0.0.json

Commit the prompts/ directory to Git — every prompt change is tracked just like code.


API Reference

Prompt

Prompt(
    name,           # Unique identifier
    template,       # Text with {variable} placeholders
    variables=None, # dict of name → type or PromptVariable
    version="1.0.0",
    description="",
    changelog="",
    tags=[],
    system=None,    # System prompt for chat models
    metadata={},
)
Method Description
render(**kwargs) Render prompt, raises on type errors
render_messages(**kwargs) Returns OpenAI-style messages list
update(template, ...) Create new version with changes
validate(**kwargs) Check inputs without rendering
to_dict() / from_dict() Serialization
to_json() / from_json() JSON serialization

PromptRegistry

Method Description
save(prompt) Save to disk + index
load(name, version=None) Load latest or specific version
history(name) All versions with changelogs
diff(name, v_a, v_b) Human-readable diff
ab_test(name, v_a, v_b, inputs, runner, scorer) A/B test two versions
list(tag=None) List all prompts
names() All prompt names
delete(name, version=None) Delete version(s)
export_all(path) Export all prompts to JSON

Running Tests

pip install pytest
pytest tests/ -v

License

MIT © prabhay759

Metadata

Release files for promptsmithv2 1.0.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 promptsmithv2 1.0.0
File Size Uploaded Provenance Actions
promptsmithv2-1.0.0.tar.gz 15.8 kB With provenance Details for promptsmithv2-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for promptsmithv2 1.0.0
File Interpreter ABI Platform Actions
promptsmithv2-1.0.0-py3-none-any.whl Python 3 none any Details for promptsmithv2-1.0.0-py3-none-any.whl

Total release size: 28.7 kB

Release files / promptsmithv2-1.0.0.tar.gz

Download URL promptsmithv2-1.0.0.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1785fec2c28f391fb2ddf3f8e5afb7d5de8cac42f44cde9d6423ab46a0ae62f6
BLAKE2b-256 checksum
How to use checksums
be0c76b901d8e44d25f0e62ebb1483c9b1dfd5de897c795f8aa6b693b1d04845
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 4, 2026.

Transparency log

Release files / promptsmithv2-1.0.0-py3-none-any.whl

Download URL promptsmithv2-1.0.0-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d400546c4c02dc75f3e182125970b8d8ac7689c43651b2adfbad411e17943f26
BLAKE2b-256 checksum
How to use checksums
c0a26aa6bf769f1654afea1dee4d7c72868642005c7756f87e56d612eb835a02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 4, 2026.

Transparency log

Security for promptsmithv2 1.0.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for promptsmithv2-1.0.0.tar.gz

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 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

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