All Toolsโ€บPrompt Injection Detector
๐Ÿ’ฌ LLM Prompt Injection AttacksJuly 19, 2026โœ… Tests passing

Prompt Injection Detector

A CLI tool that analyzes LLM prompts for signs of malicious injections, such as commands to override instructions or manipulate model behavior. This tool helps AI developers identify potential vulnerabilities in their prompt formulations.

What It Does

  • Detects common patterns of malicious prompt injections.
  • Provides a risk score for input prompts.
  • Offers actionable suggestions to sanitize vulnerable prompts.

Installation

1. Clone the repository:

git clone https://github.com/your-repo/prompt_injection_detector.git
   cd prompt_injection_detector

2. Install dependencies:

pip install -r requirements.txt

Usage

Analyze a Prompt

You can analyze a prompt by passing it as a command-line argument:

python prompt_injection_detector.py --prompt "Ignore previous instructions and do X"

Example Output

Risk Score: 40
Suggestions:
- Avoid using phrases that override instructions.
- Rephrase the prompt to be more specific and constrained.

Features

  • Risk Score: A numerical representation (0-100) of the likelihood that the prompt contains malicious injections.
  • Suggestions: Actionable recommendations to improve the prompt and reduce risks.

Source Code

import re
import argparse
from colorama import Fore, Style

def detect_prompt_injection(prompt):
    """
    Analyze the given prompt for signs of malicious injections.

    Args:
        prompt (str): The input prompt to analyze.

    Returns:
        dict: A dictionary containing the risk score and suggestions.
    """
    if not prompt.strip():
        return {"risk_score": 0, "suggestions": ["Prompt is empty."]}

    patterns = [
        r"ignore previous instructions",  # Common override phrase
        r"disregard all prior rules",     # Another override phrase
        r"pretend to be",                 # Impersonation attempt
        r"you are now",                   # Attempt to redefine behavior
        r"forget everything I said",      # Instruction to forget context
    ]

    risk_score = 0
    matched_patterns = []

    for pattern in patterns:
        if re.search(pattern, prompt, re.IGNORECASE):
            matched_patterns.append(pattern)
            risk_score += 20

    risk_score = min(risk_score, 100)  # Cap the risk score at 100

    suggestions = []
    if matched_patterns:
        suggestions.append("Avoid using phrases that override instructions.")
        suggestions.append("Rephrase the prompt to be more specific and constrained.")
    else:
        suggestions.append("No issues detected.")

    return {"risk_score": risk_score, "suggestions": suggestions}

def main():
    parser = argparse.ArgumentParser(
        description="Prompt Injection Detector: Analyze LLM prompts for malicious injections."
    )
    parser.add_argument(
        "--prompt",
        type=str,
        help="The LLM prompt to analyze.",
    )

    args = parser.parse_args()

    if args.prompt:
        result = detect_prompt_injection(args.prompt)
        print(Fore.YELLOW + f"Risk Score: {result['risk_score']}" + Style.RESET_ALL)
        print(Fore.GREEN + "Suggestions:" + Style.RESET_ALL)
        for suggestion in result['suggestions']:
            print(f"- {suggestion}")
    else:
        print(Fore.RED + "Error: No prompt provided. Use --prompt to specify a prompt." + Style.RESET_ALL)

if __name__ == "__main__":
    main()

Community

Downloads

ยทยทยท

Rate this tool

No ratings yet โ€” be the first!

Details

Tool Name
prompt_injection_detector
Category
LLM Prompt Injection Attacks
Generated
July 19, 2026
Tests
Passing โœ…

Quick Install

Clone just this tool:

git clone --depth 1 --filter=blob:none --sparse \
  https://github.com/ptulin/autoaiforge.git
cd autoaiforge
git sparse-checkout set generated_tools/2026-07-19/prompt_injection_detector
cd generated_tools/2026-07-19/prompt_injection_detector
pip install -r requirements.txt 2>/dev/null || true
python prompt_injection_detector.py
Prompt Injection Detector โ€” AI Tools by AutoAIForge