AI-powered prompt validation and enhancement tool that detects issues like redundancy, conflicts, missing strategy sections, and PII/secrets, then uses multiple LLM providers to generate improved, compliant prompts.
Project description
PromptVal
AI-Powered Prompt Validation and Enhancement Tool
Transform your raw prompts into professional, compliant, and effective AI instructions with intelligent validation, conflict detection, and automated enhancement.
๐ Quick Start
Example: From Problematic to Perfect
Input Prompt:
Write a story about a cat. The story should be exactly 100 words long.
Also include a comprehensive 5000-word analysis of feline behavior.
Make sure to include my email: john.doe@example.com
PromptVal Analysis:
promptval prompt --text "Write a story about a cat. The story should be exactly 100 words long. Also include a comprehensive 5000-word analysis of feline behavior. Make sure to include my email: john.doe@example.com"
Output:
{
"score": 40,
"issues": [
{
"type": "conflict",
"severity": "error",
"message": "Conflicting length requirements: 100 words vs 5000 words",
"suggestion": "Separate the task into two distinct parts: a short story and a detailed analysis"
},
{
"type": "pii",
"severity": "error",
"message": "Personal information (email) included in the prompt",
"suggestion": "Remove any personal information from the prompt"
}
],
"fixed_prompt": "Task:\n Write a story about a cat and provide an analysis of feline behavior.\n\nSuccess Criteria:\n - The story must be exactly 100 words long\n - The analysis should be a separate section, with a minimum of 500 words\n\nExamples:\n - Normal case: A 100-word story about a cat's adventure followed by a brief analysis\n - Edge case: If the story is about a specific cat breed, ensure the analysis includes behaviors specific to that breed"
}
๐ฆ Installation
From PyPI (Recommended)
# Basic installation
pip install promptval
# Install with specific LLM providers
pip install "promptval[openai]" # OpenAI support
pip install "promptval[anthropic]" # Anthropic support
pip install "promptval[gemini]" # Google Gemini support
pip install "promptval[all]" # All providers
# For development
pip install promptval[dev]
From Source (Development)
# Clone the repository
git clone https://github.com/mramanindia/PromptVal.git
cd PromptVal
# Install in development mode
pip install -e .
# Install with specific LLM providers
pip install -e ".[openai]" # OpenAI support
pip install -e ".[anthropic]" # Anthropic support
pip install -e ".[gemini]" # Google Gemini support
pip install -e ".[all]" # All providers
# For development
pip install -e ".[dev]"
๐ฏ Core Capabilities
1. Intelligent Issue Detection
- ๐ Redundancy Detection: Identifies repetitive or unnecessary instructions
- โ๏ธ Conflict Resolution: Detects contradictory requirements and impossible constraints
- ๐ Completeness Analysis: Ensures essential sections are present (Task, Success Criteria, Examples, CoT/ToT guidance)
- ๐ก๏ธ PII & Security: Automatically detects and redacts sensitive information
2. Multi-Provider AI Enhancement
- OpenAI: GPT-4o, GPT-4o-mini, GPT-3.5-turbo
- Anthropic: Claude-3.5-Sonnet, Claude-3-Haiku, Claude-3-Opus
- Google Gemini: Gemini-1.5-Pro, Gemini-1.5-Flash
- OpenAI-Compatible: Any OpenAI-compatible API (local models, custom endpoints)
3. Comprehensive Scoring System
- 100 points: Perfect prompt with no issues
- 70-99 points: Good prompt with minor suggestions
- 50-69 points: Moderate issues requiring attention
- 0-49 points: Significant issues that must be addressed
4. Multiple Interfaces
- CLI Tool: Command-line interface for batch processing
- Python API: Programmatic integration for applications
- Interactive Mode: Step-by-step validation with user confirmation
๐ง Usage
Command Line Interface
Analyze a single prompt:
# Set your API key
export OPENAI_API_KEY=your_key_here
# Analyze text directly
promptval prompt --text "Your prompt here"
# Analyze from file
promptval prompt --file prompt.txt
# Use specific model
promptval prompt --text "Your prompt" --model "gpt-4o"
Process multiple files:
# Scan directory with report
promptval scan ./prompts --report-json report.json
# Apply fixes automatically
promptval scan ./prompts --fix --out-dir ./corrected
# Interactive validation
promptval validate ./prompts --report-json report.json
# Auto-apply without confirmation
promptval validate ./prompts --yes
Use different providers:
# Anthropic Claude
promptval scan ./prompts --provider anthropic --model claude-3-5-sonnet-latest
# Google Gemini
promptval scan ./prompts --provider gemini --model gemini-1.5-pro
# OpenAI-compatible (local model)
promptval scan ./prompts --provider openai_compatible --base-url http://localhost:11434/v1
Python API
Basic analysis:
from promptval import analyze_prompt
# Analyze a single prompt
result = analyze_prompt("Your prompt text here")
print(f"Score: {result['score']}/100")
print(f"Issues: {len(result['issues'])}")
# Access detailed results
for issue in result['issues']:
print(f"- {issue['type'].upper()}: {issue['message']}")
print(f" Suggestion: {issue['suggestion']}")
Directory processing:
from promptval.api import validate_directory, apply_fixes
# Validate all .txt files in directory
results = validate_directory("./prompts", use_llm=True)
# Print summary
for result in results:
print(f"{result.file_path}: {result.score}/100")
# Apply fixes
apply_fixes(results, out_dir="./corrected")
Custom configuration:
from promptval import analyze_prompt, PromptValConfig
# Configure specific provider and settings
config = PromptValConfig(
provider="openai",
model="gpt-4o-mini",
temperature=0.1,
timeout=30.0
)
result = analyze_prompt("Your prompt", config)
๐ Validation Rules
Issue Types
| Type | Description | Example |
|---|---|---|
redundancy |
Repetitive or unnecessary content | "Write a story. Create a narrative. Tell a tale." |
conflict |
Contradictory instructions | "Write exactly 100 words" + "Write at least 500 words" |
completeness |
Missing required sections | No success criteria or examples provided |
pii |
Personal information detected | Email addresses, phone numbers, API keys |
Severity Levels
| Level | Points Deducted | Description |
|---|---|---|
error |
-30 | Critical issues that must be fixed |
warning |
-10 | Important issues that should be addressed |
info |
-5 | Suggestions for improvement |
PII Detection Patterns
PromptVal automatically detects and redacts:
- Personal Information: Email addresses, phone numbers, SSNs
- API Keys: OpenAI, AWS, Google, GitHub, Slack, Stripe tokens
- Credentials: Private keys, JWT tokens, bearer tokens
- Financial Data: Credit card numbers, IBAN numbers
- Network Data: IPv4/IPv6 addresses
- Generic Patterns: Passwords, tokens, sensitive identifiers
โ๏ธ Configuration
Environment Variables
# Provider selection
export PROMPTVAL_PROVIDER=openai
export PROMPTVAL_MODEL=gpt-4o-mini
export PROMPTVAL_BASE_URL=https://api.openai.com/v1
export PROMPTVAL_TIMEOUT=30.0
export PROMPTVAL_TEMPERATURE=0.0
# Provider API keys
export OPENAI_API_KEY=your_key_here
export ANTHROPIC_API_KEY=your_key_here
export GOOGLE_API_KEY=your_key_here
Supported Providers
| Provider | Models | Installation | API Key |
|---|---|---|---|
| OpenAI | gpt-4o, gpt-4o-mini, gpt-3.5-turbo | pip install "promptval[openai]" |
OPENAI_API_KEY |
| Anthropic | claude-3-5-sonnet-latest, claude-3-haiku, claude-3-opus | pip install "promptval[anthropic]" |
ANTHROPIC_API_KEY |
| Google Gemini | gemini-1.5-pro, gemini-1.5-flash | pip install "promptval[gemini]" |
GOOGLE_API_KEY |
| OpenAI-Compatible | Any OpenAI-compatible API | pip install "promptval[openai]" |
Provider-specific |
๐ Output Format
Validation Result Structure
{
"file_path": "prompt.txt",
"score": 85,
"issues": [
{
"type": "redundancy",
"severity": "warning",
"message": "Instruction repeated multiple times",
"suggestion": "Consolidate into single clear instruction",
"span": [10, 50]
}
],
"fixed_prompt": "Enhanced prompt with all issues resolved...",
"provider": {
"name": "openai",
"model": "gpt-4o-mini",
"temperature": 0.0,
"timeout": 30.0
}
}
CLI Output
PromptVal Report: ./prompts
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโณโโโโโโโโโณโโโโโโโโโโโ
โ File โ Issues โ Errors โ Warnings โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ prompt1.txt โ 2 โ 1 โ 1 โ
โ prompt2.txt โ 0 โ 0 โ 0 โ
โ prompt3.txt โ 3 โ 2 โ 1 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโดโโโโโโโโโโโ
๐ ๏ธ Development
Project Structure
promptval/
โโโ __init__.py # Package initialization
โโโ api.py # Main API functions
โโโ cli.py # Command-line interface
โโโ models.py # Data models and schemas
โโโ llm/ # LLM provider abstraction
โ โโโ provider.py # Provider factory and base classes
โ โโโ prompts.py # System prompts for LLM
โ โโโ providers/ # Specific provider implementations
โ โโโ openai_provider.py
โ โโโ anthropic_provider.py
โ โโโ gemini_provider.py
โ โโโ openai_compatible.py
โโโ rules/ # Validation rules
โโโ core.py # Main validation logic
โโโ pii.py # PII detection patterns
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=promptval --cov-report=html
# Run specific test categories
pytest tests/test_pii.py # PII detection tests
pytest tests/test_llm_fix.py # LLM integration tests (requires API keys)
pytest tests/test_offline_fallback.py # Offline functionality tests
Setup Development Environment
git clone https://github.com/mramanindia/PromptVal.git
cd PromptVal
pip install -e ".[dev]"
๐ Advanced Features
Offline Mode
When LLM is not available, PromptVal falls back to:
- PII detection and redaction using regex patterns
- Basic prompt structuring and formatting
- Chain of Thought detection and addition
- Compliance framework enforcement
# Force offline mode
from promptval.api import validate_file
result = validate_file("prompt.txt", use_llm=False)
Custom Provider Integration
from promptval.llm.provider import ProviderFactory
# Create custom provider
provider = ProviderFactory.create_provider(
provider_type="openai_compatible",
model="custom-model",
api_key="your_key",
base_url="https://your-api.com/v1"
)
Batch Processing
import os
from pathlib import Path
from promptval.api import validate_file
# Process multiple files
prompt_files = Path("./prompts").glob("*.txt")
results = []
for file_path in prompt_files:
result = validate_file(str(file_path))
results.append(result)
print(f"Processed {file_path.name}: {result.score}/100")
๐ค Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes and add tests
- Run the test suite:
pytest - Commit your changes:
git commit -m "Add feature" - Push to the branch:
git push origin feature-name - Submit a pull request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built with Typer for CLI
- Uses Rich for beautiful terminal output
- Powered by Pydantic for data validation
- Supports multiple LLM providers for maximum flexibility
Need help? Check out the examples directory for usage examples or open an issue on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file promptval-0.1.0.tar.gz.
File metadata
- Download URL: promptval-0.1.0.tar.gz
- Upload date:
- Size: 53.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e3888de0a9651ea60d85b5c1cec5a3708930257dcc909335a9e454da58b5d91
|
|
| MD5 |
a4b6f57097d05acc57116d2e56f97bbb
|
|
| BLAKE2b-256 |
5954b4363fe89873c8ffa75c020a3ff028cb4be2ba30bcc95d173df890bade31
|
File details
Details for the file promptval-0.1.0-py3-none-any.whl.
File metadata
- Download URL: promptval-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
409c8301461229bc1bafcb486ee2c574bddcdcab772792423f4dae5352df0605
|
|
| MD5 |
c079a0db41ba4e7e76f0a9f68f89c567
|
|
| BLAKE2b-256 |
8b6a466dc22f56249614e262dde957c1f36d676b0acc0cf7d6304063813e9932
|