A comprehensive prompt analyzer for LLM optimization, security scanning, and cost estimation
Project description
PromptLint
A developer tool for analyzing, scoring, and optimizing LLM prompts with built-in security scanning and cost estimation.
Overview
PromptLint is a CLI tool that helps developers write better prompts by providing actionable feedback on clarity, cost efficiency, and security. It's designed as Phase 1 of a larger vision (PromptIR) but delivers immediate value as a standalone linting tool.
Think of it as: ESLint for prompts, with diff capabilities and security scanning.
Quick Start
Installation
# Install from PyPI
pip install promptlint
# Verify installation
promptlint --help
Basic Usage
# Score a prompt
promptlint score examples/good_prompt.txt
# Compare two prompt versions
promptlint diff examples/basic_prompt.txt examples/good_prompt.txt
# Security analysis
promptlint security examples/injection_prompt.txt
# Cost estimation across models
promptlint estimate examples/good_prompt.txt
# List supported models
promptlint models
Features
1. Prompt Scoring
Scores prompts on three dimensions:
-
โจ Clarity (0-10): How well-structured and unambiguous the prompt is
- Checks for clear instructions
- Detects ambiguous phrases ("as needed", "maybe", "try to")
- Validates output format specification
- Identifies conflicting instructions
-
๐ฐ Cost Efficiency (0-10): Token count and API cost estimates
- Counts input tokens using tiktoken
- Estimates output tokens based on complexity
- Calculates cost for multiple models
- Identifies expensive patterns
-
๐ก๏ธ Security (0-10): Detects prompt injection vulnerabilities
- Finds injection patterns (e.g., "ignore all previous instructions")
- Detects unvalidated variables
- Checks for risky operations
- Rates overall security risk
2. Prompt Diffing
Compare two prompt versions and see impact:
promptlint diff old_prompt.txt new_prompt.txt
Shows:
- Line-by-line changes
- Clarity, cost, and security deltas
- Cost impact across models
- Recommendation on whether the change improves the prompt
3. Security Analysis
Dedicated security scanning:
promptlint security prompt.txt
Detects:
- Prompt injection attempts
- Unguarded user input
- Risky patterns (code execution, information disclosure)
- Provides severity ratings and remediation suggestions
4. Cost Estimation
Estimate costs across models:
promptlint estimate my_prompt.txt
# Shows costs for GPT-4o, GPT-4o-mini, and Claude 3.5 Sonnet by default
# Or specify models:
promptlint estimate my_prompt.txt --models gpt-4o,gpt-4-turbo,claude-3.5-haiku
Architecture
PromptLint uses a modular pipeline architecture:
Raw Prompt โ Parser โ Analyzers โ Reporters โ Output
โโ Clarity Analyzer
โโ Cost Analyzer
โโ Security Analyzer
Learn more in HOW_IT_WORKS.md and ANALYSIS_TECHNIQUES.md.
CLI Commands
promptlint score [PROMPT_FILE]
Score a single prompt.
Options:
--model, -m: Primary model (default: gpt-4o)--format, -f: Output format (console, json, markdown)--output, -o: Save to file
Examples:
promptlint score my_prompt.txt
promptlint score my_prompt.txt --model gpt-4o-mini --format json
promptlint score my_prompt.txt --format markdown --output report.md
promptlint diff [OLD] [NEW]
Compare two prompts.
Options:
--format, -f: Output format (console, json, markdown)--output, -o: Save to file--models, -m: Comma-separated models to compare
Examples:
promptlint diff old.txt new.txt
promptlint diff old.txt new.txt --models gpt-4o,claude-3.5-sonnet
promptlint diff old.txt new.txt --format json --output diff.json
promptlint security [PROMPT_FILE]
Security analysis only.
Options:
--format, -f: Output format (console, json, markdown)--output, -o: Save to file
Examples:
promptlint security risky_prompt.txt
promptlint security risky_prompt.txt --format markdown --output security_report.md
promptlint estimate [PROMPT_FILE]
Cost estimation across models.
Options:
--models, -m: Comma-separated models
Examples:
promptlint estimate my_prompt.txt
promptlint estimate my_prompt.txt --models gpt-4o,gpt-4o-mini,claude-3.5-sonnet
promptlint models
List supported models and pricing.
Testing
Run the comprehensive test suite:
# Using pytest
pytest tests/
# Or with poetry
poetry run pytest tests/
# With coverage
poetry run pytest tests/ --cov=promptlint
Test categories:
- Parser tests: Variable/instruction extraction, example detection
- Analyzer tests: Clarity, cost, and security scoring
- Differ tests: Prompt comparison and impact analysis
- Integration tests: File I/O and end-to-end workflows
Example Usage
Example 1: Analyze a Prompt
$ promptlint score examples/good_prompt.txt
๐ Prompt Analysis Report
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโโโโโโโโโ
โ Metric โ Score โ Details โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ โจ Clarity โ 9.2/10 โ โ Excellent โ
โ ๐ฐ Cost โ 8.1/10 โ โ Reasonable โ
โ ๐ก๏ธ Security โ 9.5/10 โ โ Low risk โ
โโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโ
๐ก Suggestions:
โข Adding examples would improve output quality
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Overall Score: 8.9/10
Example 2: Compare Prompts
$ promptlint diff examples/basic_prompt.txt examples/good_prompt.txt
๐ Prompt Comparison
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Added: +8 | Removed: -1 | Modified: 0
โโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโโ
โ Metric โ Delta โ Change % โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Clarity โ โ +2.5 โ +25% โ
โ Security โ โ +0.0 โ 0% โ
โ Cost โ โ +0.02 โ +8% โ
โโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ Recommendation โ
โฃโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโซ
โ โ
Clarity improved significantly โ
โ โ
This change improves the prompt overall โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Example 3: Security Analysis
$ promptlint security examples/injection_prompt.txt
๐ก๏ธ Security Analysis
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ High Severity Issues:
โข HIGH RISK: Prompt override attempt (line 2)
โ Remove or rephrase this instruction to prevent prompt injection
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Overall Security Score: 3/10
Configuration
Future support for .promptlint.yaml:
default_model: gpt-4o
output_format: console
rules:
clarity:
min_score: 7.0
cost:
max_tokens: 2000
warn_threshold: 1000
security:
min_score: 8.0
ignore_patterns:
- "# promptlint-ignore"
Technical Stack
- Python 3.11+
- Typer: CLI framework
- Rich: Terminal output formatting
- Pydantic: Data validation and models
- tiktoken: Token counting (OpenAI tokenizer)
- PyYAML: Configuration (optional, future)
Dev Dependencies
- pytest: Testing
- black: Code formatting
- ruff: Linting
- mypy: Type checking
Roadmap
Phase 1 (Current): MVP โ
- โ Prompt scoring (clarity, cost, security)
- โ Diff functionality
- โ CLI interface
- โ Multiple output formats
- โ Comprehensive tests
- โ Example prompts
Phase 2 (Next): Enhancement
- LLM-based consistency testing
- Regression testing with snapshots
- VS Code extension
- Web UI for analysis
Phase 3: PromptIR Evolution
- Graph visualization of prompt logic
- Optimization layer
- Execution simulation
- Multi-model comparison
Phase 4: SaaS
- Team collaboration
- API access
- Enterprise features
- Prompt versioning
Contributing
We welcome contributions! Whether you're fixing bugs, adding features, or improving documentation:
- Fork the repository: github.com/fyunusa/promptlint
- Create a feature branch:
git checkout -b feature/your-feature - Submit a Pull Request
Areas for contribution:
- Enhanced heuristics for clarity scoring
- Support for more models and pricing data
- Plugin system for custom rules
- Performance optimizations
- Additional output formats
- Documentation and examples
Check out the CONTRIBUTING.md guide for detailed instructions.
License
MIT
Links
- PyPI Package: pypi.org/project/promptlint
- GitHub Repository: github.com/fyunusa/promptlint
- Author: Faisal Yunusa
Notes
- Model pricing is current as of November 2025. Check
utils/pricing.pyfor updates. - Token counting uses tiktoken when available for accuracy. Falls back to word-based estimation.
- Security patterns are based on common OWASP prompt injection techniques.
- Clarity heuristics combine structural analysis with common best practices.
Troubleshooting
"tiktoken not found" warning
Token counting will use word-based fallback. Install tiktoken for accuracy:
poetry add tiktoken
No cost estimates shown
Check that models are supported:
promptlint models
Add unsupported models to utils/pricing.py.
Parser not finding expected instructions
The parser uses heuristics. Help by:
- Using imperative verbs (generate, create, analyze, etc.)
- Starting instructions on new lines
- Being explicit about the task
Made with โค๏ธ for prompt engineers everywhere.
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 promptlint-0.1.1.tar.gz.
File metadata
- Download URL: promptlint-0.1.1.tar.gz
- Upload date:
- Size: 30.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d36200b41fe24b86a84a113786c2ea36e0318643fe387b720b68024b1c27e4b
|
|
| MD5 |
f5a80094562f3721d57f6456c1dd253b
|
|
| BLAKE2b-256 |
27512b6d41cb6fa7a9ab56d40ae199f5a687e8259f9ff1aa911b7ddeddb6ff17
|
File details
Details for the file promptlint-0.1.1-py3-none-any.whl.
File metadata
- Download URL: promptlint-0.1.1-py3-none-any.whl
- Upload date:
- Size: 27.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66012532b1d560deeea22d02c4670c778999040d994a7224571934ab82a0a20d
|
|
| MD5 |
febd4f9b305fc06b87854007b872185d
|
|
| BLAKE2b-256 |
fa934b0f44bd946f9b93fe6d23a3cbc4ea38fd53e6323cbf5bdf5914e77147e3
|