Skip to main content

LLM Prompt Semantic Diff

A CLI tool for managing and comparing LLM prompts using semantic diffing instead of traditional text-based comparison.

License Python

Overview

LLM Prompt Semantic Diff delivers a lightweight command‑line workflow for managing, packaging, and semantic diffing of Large Language Model prompts. It addresses the blind spot where ordinary text‑based git diff fails to reveal meaning‑level changes that materially affect model behaviour.

Read More: https://medium.com/@aatakansalar/catching-prompt-regressions-before-they-ship-semantic-diffing-for-llm-workflows-feb3014ccac3

Key Features

  • F-1: prompt init - Generates skeletal prompt files and default manifests
  • F-2: prompt pack - Embeds prompts into .pp.json with semantic versioning
  • F-3: prompt diff - Semantic comparison with percentage scores and exit codes
  • F-4: Dual embedding providers (OpenAI cloud + SentenceTransformers local)
  • F-5: JSON output for CI/CD integration
  • F-6: Schema validation for all manifests
  • F-7: Comprehensive test suite with >75% coverage

Installation

Install from source:

git clone https://github.com/aatakansalar/llm-prompt-semantic-diff
cd llm-prompt-semantic-diff
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -e .

Quick Start

1. Initialize a New Prompt

prompt init my-greeting

Creates my-greeting.prompt and my-greeting.pp.json with default structure.

2. Package an Existing Prompt

prompt pack my-prompt.prompt

Generates embeddings and creates a versioned manifest.

3. Compare Prompt Versions

# Human-readable output
prompt diff v1.pp.json v2.pp.json --threshold 0.8

# JSON output for CI/CD
prompt diff v1.pp.json v2.pp.json --json --threshold 0.8

Returns exit code 1 if similarity below threshold.

4. Validate Manifest Schema

prompt validate my-prompt.pp.json

Embedding Providers

Local (Default)

Uses SentenceTransformers with all-MiniLM-L6-v2 model:

prompt pack my-prompt.prompt --provider sentence-transformers

Cloud (OpenAI)

Requires OPENAI_API_KEY environment variable:

export OPENAI_API_KEY="your-api-key"
prompt pack my-prompt.prompt --provider openai

CI/CD Integration

Use --json flag for machine-readable output:

- name: Check prompt changes
  run: |
    prompt diff main.pp.json feature.pp.json --json --threshold 0.8
    if [ $? -eq 1 ]; then
      echo "Prompt changes exceed threshold - review required"
      exit 1
    fi

Manifest Format

Prompts are packaged into .pp.json files:

{
  "content": "Your prompt text here...",
  "version": "0.1.0",
  "embeddings": [0.1, -0.2, 0.3, ...],
  "description": "Optional description",
  "tags": ["category", "type"],
  "model": "gpt-4"
}

Example Workflow

# Create new prompt
prompt init greeting

# Edit greeting.prompt file
# ... make changes ...

# Package with embeddings
prompt pack greeting.prompt

# Create modified version
cp greeting.prompt greeting-v2.prompt
# ... make more changes ...
prompt pack greeting-v2.prompt

# Compare versions
prompt diff greeting.pp.json greeting-v2.pp.json

# Output:
# Semantic similarity: 85.2%
# Threshold: 80.0%
# Above threshold: Yes
# Version A: 0.1.0
# Version B: 0.1.0

Security & Privacy

  • Local-first: No data leaves your machine unless OpenAI provider is explicitly selected
  • API keys: Only read from environment variables (OPENAI_API_KEY)
  • No telemetry: No analytics, tracking, or hidden network calls

Development

git clone https://github.com/aatakansalar/llm-prompt-semantic-diff
cd llm-prompt-semantic-diff
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -e ".[dev]"
pytest tests/ -v

License

Licensed under the MIT License. See LICENSE for details.

Metadata

Release files for llm-prompt-semantic-diff 0.1.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 llm-prompt-semantic-diff 0.1.0
File Size Uploaded Provenance
llm_prompt_semantic_diff-0.1.0.tar.gz 10.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-prompt-semantic-diff 0.1.0
File Interpreter ABI Platform
llm_prompt_semantic_diff-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.8 kB

Release files / llm_prompt_semantic_diff-0.1.0.tar.gz

Download URL llm_prompt_semantic_diff-0.1.0.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8735fe450a8cc1c794daaf3496458b8702f98ed631b1eb9cabdabf73e5690dd9
BLAKE2b-256 checksum
How to use checksums
440f92d0c0a54daef97854207c4d76435ef51cedb27dff855b3126d027d3ad04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.5

Release files / llm_prompt_semantic_diff-0.1.0-py3-none-any.whl

Download URL llm_prompt_semantic_diff-0.1.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27e79b8b60b9c3dfa40fd9888b3c8c0005f310c8fbaa9d4961fe79769ae408ed
BLAKE2b-256 checksum
How to use checksums
c7a0473ac2ad7a7fc639f87619617a49845b2df5670fb21c93f87e086b50c973
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.5

Security for llm-prompt-semantic-diff 0.1.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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

0.1.0 This release

2 release files No 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