Skip to main content

AI prompt security scanner with differential validation - detects vulnerabilities before they reach production

Project description

๐Ÿ›ก๏ธ PromptSentry

AI Prompt Security Scanner - Detect and prevent vulnerabilities in AI prompts before they reach production.

Python 3.9+ License: MIT OWASP LLM Top 10


๐Ÿš€ Features

  • 3-Stage Security Pipeline: Comprehensive analysis using prompt detection, pattern matching, and optional LLM validation
  • OWASP LLM Top 10 2025 Rules: Industry-standard vulnerability detection loaded as context
  • Differential Validation: No "moving goalposts" - only blocks for previously identified unfixed issues
  • Git Pre-commit Hook: Automatic scanning before every commit
  • Beautiful CLI: Rich terminal output with actionable recommendations
  • Local LLM Analysis: Uses Ollama with Qwen 2.5 Coder 0.5B (~500MB) for intelligent security assessment
  • Stable Fingerprinting: Advanced code normalization ensures issues are tracked across refactoring

๐Ÿ“ฆ Installation

pip install promptsentry

โšก Quick Start

# Initialize PromptSentry
promptsentry init

# Install git pre-commit hook
cd your-project
promptsentry install-hook

# Scan a file manually
promptsentry scan chatbot.py

# Scan without LLM (faster, pattern matching only)
promptsentry scan --no-llm chatbot.py

๐Ÿ” How It Works

PromptSentry uses a 3-stage pipeline to detect vulnerabilities:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  1. DETECT  โ”‚ -> โ”‚  2. PATTERNS โ”‚ -> โ”‚ 3. SLM      โ”‚
โ”‚   Prompts   โ”‚    โ”‚    Check     โ”‚    โ”‚   ANALYSIS  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  Fast filter       OWASP LLM Top 10    Ollama + Qwen
   (0.1s)           rules (0.2s)        (optional, 2s)

Stage 1: Prompt Detection

Quickly identifies AI prompts in source code using heuristics and pattern matching.

Stage 2: Pattern Matching

Applies OWASP LLM Top 10 2025 rules for deterministic vulnerability detection.

Stage 3: SLM Analysis (Optional)

Uses Ollama with Qwen 2.5 Coder 0.5B for intelligent, context-aware vulnerability assessment. OWASP rules are passed as context to the model for comprehensive analysis.


๐Ÿ›ก๏ธ Vulnerabilities Detected

Based on OWASP LLM Top 10:

Category Description Detection
LLM01 Prompt Injection Direct concatenation, missing delimiters, weak system prompts
LLM02 Sensitive Information Disclosure PII, credentials, API keys in prompts
LLM03 Supply Chain Vulnerabilities Vulnerable dependencies, untrusted models/data
LLM04 Data and Model Poisoning Poisoned training data, malicious fine-tuning
LLM05 Improper Output Handling eval(), exec(), subprocess, SQL/XSS from LLM output
LLM06 Excessive Agency Unrestricted file/network access, auto-execution
LLM07 System Prompt Leakage Extractable logic, secrets in system prompts
LLM08 Vector and Embedding Weaknesses RAG poisoning, embedding manipulation
LLM09 Misinformation Hallucinations, lack of factual grounding
LLM10 Unbounded Consumption No rate limiting, infinite loops, resource exhaustion

๐Ÿ’ก Key Innovation: Differential Validation

PromptSentry tracks issues across commits and only blocks for previously identified unfixed issues:

  1. First scan: Detects issues and tracks them
  2. Fix and commit: Only checks if tracked issues are fixed
  3. No moving goalposts: New findings are noted but don't block

This prevents the frustrating experience of fixing one issue only to have the scanner find new nitpicks.


๐Ÿ“‹ CLI Commands

Setup

promptsentry init              # Initialize PromptSentry
promptsentry install-hook      # Install git pre-commit hook
promptsentry uninstall-hook    # Remove the hook

Scanning

promptsentry scan file.py      # Scan a single file (LLM enabled by default)
promptsentry scan .            # Scan current directory
promptsentry scan --staged     # Scan staged git files
promptsentry scan --no-llm     # Disable LLM for faster scanning

Issue Management

promptsentry issues list       # List tracked issues
promptsentry issues stats      # Show statistics
promptsentry issues clear file.py  # Clear issues for a file
promptsentry issues ignore ID  # Ignore a specific issue

Configuration

promptsentry config show       # Show current config
promptsentry config set scan.threshold 80  # Set blocking threshold
promptsentry config reset      # Reset to defaults

Rules

promptsentry rules            # List all detection rules

โš™๏ธ Configuration

Configuration is stored in ~/.promptsentry/config.yaml:

scan:
  threshold: 50              # Score to block (0-100)
  min_confidence: 0.6        # Prompt detection threshold
  file_extensions:
    - .py
    - .js
    - .ts

llm:
  model_name: qwen2.5-coder:0.5b  # Ollama model
  enabled: true                    # Enable LLM analysis by default
  timeout: 30                      # LLM request timeout (seconds)
  
hook:
  enabled: true
  block_on_issues: true
  allow_bypass: true         # Allow --no-verify

๐ŸŽฌ Demo Flow

# First commit - issues detected
$ git add chatbot.py
$ git commit -m "Add chatbot"

๐Ÿ” PromptSentry: Scanning staged files...
   โœ“ Found 1 prompt in chatbot.py

โŒ COMMIT BLOCKED - 2 vulnerabilities found

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
๐Ÿ”ด HIGH - Direct Concatenation
   chatbot.py:15

   Problem:
   > prompt = "Translate: " + user_input

   Fix:
   > prompt = f"Translate: <input>{user_input}</input>"
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

# Fix and commit again
$ git commit -m "Fix: Add delimiters"

๐Ÿ” PromptSentry: Checking fixes...

โœ… Fixed: Direct Concatenation โœ“

๐ŸŽ‰ All vulnerabilities resolved!
โœ… COMMIT ALLOWED

๐Ÿ”ง Development

# Clone repository
git clone https://github.com/Brightlord5/PromptGuard
cd PromptGuard

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
black promptsentry
ruff check promptsentry

๐Ÿ“„ License

MIT License - see LICENSE for details.


๐Ÿ™ Acknowledgments

  • OWASP LLM Top 10 for vulnerability categories
  • Ollama for local LLM infrastructure
  • Qwen for the efficient coder model
  • Rich for beautiful terminal output

Made with โค๏ธ for secure AI development

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

promptsentry-0.1.7.tar.gz (75.1 kB view details)

Uploaded Source

Built Distribution

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

promptsentry-0.1.7-py3-none-any.whl (85.9 kB view details)

Uploaded Python 3

File details

Details for the file promptsentry-0.1.7.tar.gz.

File metadata

  • Download URL: promptsentry-0.1.7.tar.gz
  • Upload date:
  • Size: 75.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for promptsentry-0.1.7.tar.gz
Algorithm Hash digest
SHA256 8f7b29e058a65e01d8a4233b366b022f278b710f4560530db4e851bd238428ba
MD5 aa0760ae42e5f5dd4ec2446e72972315
BLAKE2b-256 2b6e420fe55635e0935db532c90a3cc97ca5fa00639d2e3a705ceea1add4d748

See more details on using hashes here.

File details

Details for the file promptsentry-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: promptsentry-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 85.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for promptsentry-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b4259150628999fba18d8a5e9a6a1d9384760d19176bba5fb6e253d5a5206f64
MD5 d13ec7c7788f4b3290511d641e304c9a
BLAKE2b-256 ad7e913e12b32ab1d326e42836b65a7c15b434548278e69426b341f5dc93d0ab

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