Skip to main content

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:

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


Notes

  • Model pricing is current as of November 2025. Check utils/pricing.py for 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.

Metadata

Release files for promptlint 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for promptlint 0.1.1
File Size Uploaded
promptlint-0.1.1.tar.gz 30.9 kB Details

Built distribution (wheel)

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

Total release size: 58.7 kB

Release files / promptlint-0.1.1.tar.gz

Download URL promptlint-0.1.1.tar.gz
Size 30.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1d36200b41fe24b86a84a113786c2ea36e0318643fe387b720b68024b1c27e4b
BLAKE2b-256 checksum
How to use checksums
27512b6d41cb6fa7a9ab56d40ae199f5a687e8259f9ff1aa911b7ddeddb6ff17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / promptlint-0.1.1-py3-none-any.whl

Download URL promptlint-0.1.1-py3-none-any.whl
Size 27.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66012532b1d560deeea22d02c4670c778999040d994a7224571934ab82a0a20d
BLAKE2b-256 checksum
How to use checksums
fa934b0f44bd946f9b93fe6d23a3cbc4ea38fd53e6323cbf5bdf5914e77147e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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