Skip to main content

Automated Reverse Prompt Engineering: Evolve system prompts from target outputs.

Project description

PromptSearch

PyPI version License: MIT

Automated Reverse Prompt Engineering: Evolve system prompts from target outputs.

Installation

pip install promptsearch

Quick Start

from promptsearch import PromptSearcher

# Define your target output (what you want the LLM to produce)
target_output = {
    "phone": "555-1234",
    "name": "John Doe"
}

# Define your initial system prompt
initial_prompt = "Extract information from the text."

# Create the searcher
searcher = PromptSearcher(
    target_output=target_output,
    initial_prompt=initial_prompt
)

# Run optimization
train_input = "Contact John Doe at 555-1234 for more information."
result = searcher.optimize(train_input=train_input, generations=5)

print(f"Best Prompt: {result['best_prompt']}")
print(f"Best Score: {result['best_score']:.3f}")
print(f"Best Output: {result['best_output']}")

How It Works

PromptSearch uses evolutionary hill climbing to optimize system prompts:

  1. Generate: Test the current prompt with your input
  2. Score: Compare output to target using semantic similarity
  3. Mutate: Use an LLM to rewrite the prompt based on failure analysis
  4. Repeat: Continue until convergence or max generations

Requirements

  • Python 3.8+
  • OpenAI API key (set OPENAI_API_KEY environment variable)

License

MIT License - see LICENSE file for details.

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

promptsearch-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

promptsearch-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: promptsearch-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for promptsearch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0865109d10ab76ecb71bc4d2f2c61a885e9c28637bcda9e3c9d4079eb512baf
MD5 39766572acba61ac01b16f82ebdf3e74
BLAKE2b-256 874c3b701e29cbd17e49980af56e10b42fac32d5d2a86d9d1b2d06156a23ad74

See more details on using hashes here.

File details

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

File metadata

  • Download URL: promptsearch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for promptsearch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e13aaa19ad7ec76a4a94cd8309d075a830a7a5b5af94b014985b731c30599cd
MD5 e3db177adf2f9a6ffced9fe0e4c50f94
BLAKE2b-256 90bedd8f6ab06ab81f68338f3b05d74346334f87725527eb2e18159648fdcf6e

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