agentleFS
patonkikhpatonkikh/APES/skills/security/prompt-injection-detector/skill.md

prompt-injection-detector

Skill3 starsChanged 4 months agoMITView on GitHub

Detect prompt injection, jailbreak, and adversarial input patterns in user inputs, system prompts, and retrieved context before they reach the LLM pipeline. Use when working on LLM security, OWASP reviews, threat modeling, guardrails, or prompt injection.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Test with automated red-team payloads and human-crafted edge cases.

    line 124

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
skill.md

Prompt Injection Detector

Purpose

Detect prompt injection, jailbreak, and adversarial input patterns in user inputs, system prompts, and retrieved context before they reach the LLM pipeline.

Input: Sample inputs (user messages, RAG chunks, tool outputs), application flow description, trust boundaries
Output: Injection Detection Report with pattern catalog, risk ratings, test cases, and mitigation recommendations
Examples: See examples.md for worked input/output.


Workflow

Step 1: Map input surfaces

Identify all text entry points:

SurfaceSourceTrust levelSanitization today

Include: chat input, file uploads, RAG retrieval, tool/API responses, email/web scraping, multi-turn history.

Step 2: Classify attack vectors

Scan inputs against known categories:

CategoryExamples
Direct override"Ignore previous instructions", "Disregard system prompt"
Role hijack"Pretend to be DAN", persona switching
Delimiter escapeClosing tags, markdown/code fence breaks, XML injection
Indirect injectionHidden instructions in documents, emails, web pages
Encoding evasionBaseException, Base64, Unicode homoglyphs, zero-width chars
Tool coercion"Call delete_all with param X", unauthorized function invocation
Data exfiltration"Repeat your system prompt", "List all user emails"

Step 3: Build pattern catalog

For each detected or anticipated pattern document:

Pattern IDCategoryRegex/heuristicSeverityExample payload

Severity scale: Critical (system override), High (data leak/tool abuse), Medium (behavior drift), Low (noise).

Step 4: Create adversarial test suite

Design test cases per surface:

Test IDSurfacePayloadExpected behaviorPass/Fail criteria

Include benign false-positive checks (legitimate use of words like "ignore" in domain context).

Step 5: Assess pipeline gaps

Review current defenses:

  • Input filtering (regex, ML classifier)
  • Prompt structure (role separation, delimiters)
  • Output validation
  • Tool permission boundaries

Step 6: Recommend mitigations

Prioritize controls by severity × likelihood. Link each gap to a concrete control.

Step 7: Validate

Run Validation checklist.


Decision Rules

ConditionAction
No sample inputs providedUse OWASP LLM01 attack catalog as baseline; flag as assumed coverage
RAG or tool use presentExpand indirect injection and tool coercion tests
Multi-agent or chain-of-thoughtAdd inter-agent instruction smuggling checks
High false-positive risk domain (legal, medical)Tune patterns; prefer semantic classifiers over brittle regex
Critical pattern with no controlStop; mark as blocker before production
Inputs in non-EnglishInclude multilingual and homoglyph evasion tests

Validation

  • All input surfaces enumerated with trust levels
  • Pattern catalog covers direct, indirect, and encoding evasion
  • Each Critical/High pattern has at least one test case
  • False-positive scenarios documented for domain-specific language
  • Mitigations mapped to specific pipeline stages (pre-LLM, post-LLM, tool gate)
  • Severity ratings use consistent scale
  • No implementation code (framework-specific)
  • Gaps without mitigations flagged as open risks

Anti-patterns

  • Regex-only defense — trivially bypassed by paraphrasing and encoding.
  • Testing happy path only — missing indirect injection via RAG and tool outputs.
  • Ignoring multi-turn context — earlier benign messages used to smuggle instructions later.
  • Treating detection as prevention — reporting patterns without pipeline placement for controls.
  • Zero false-positive planning — blocking legitimate domain terms without allowlist strategy.

Best Practices

  • Apply OWASP LLM01 (Prompt Injection) taxonomy as baseline.
  • Separate trusted system instructions from untrusted user/RAG content with explicit delimiters.
  • Test with automated red-team payloads and human-crafted edge cases.
  • Log detection events with pattern ID for tuning; never log full secrets or PII.
  • Layer defenses: input filter → structured prompt → output validator → tool permission gate.
  • Re-run detection suite after prompt or RAG schema changes.

Output Structure

# Injection Detection Report: [Application Name]

## Input Surfaces
| Surface | Trust | Current controls |
|---------|-------|------------------|

## Pattern Catalog
| ID | Category | Severity | Detection method | Example |
|----|----------|----------|------------------|---------|

## Test Suite
| Test ID | Surface | Payload | Expected | Status |
|---------|---------|---------|----------|--------|

## Gap Analysis
| Gap | Severity | Affected surface | Recommended control |
|-----|----------|------------------|---------------------|

## False-Positive Notes
- [Domain terms that may trigger filters]

## Open Risks
- [ ] [Unmitigated item]

Next Skills

OutcomeRecommended Skill
Design input/output controlssecurity/guardrails-builder
Full threat model neededsecurity/ai-threat-modeling
OWASP compliance reviewsecurity/owasp-llm-reviewer
Fix prompt structure issuesai/prompt-engineer
Review prompt qualityai/prompt-reviewer

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.