prompt-injection-defense
Skill0 starsChanged 6 months agoMITView on GitHub
Detects and blocks prompt injection attempts in user input before they reach the LLM. Use when agents accept free-text user input, when handling untrusted data in RAG pipelines, or when compliance requires logging and blocking jailbreak attempts.
7 other projects use a version of this.
Adopted by
Most recently taken up by
- DevelopersGlobal/ai-agent-skillstheir own version, first seen Oct 25, 2026
- mikulgohil/claude-skillstheir own version, first seen Oct 13, 2026
- smitshivalkar-spectims4567/hsj-agent-skillstheir own version, first seen Sep 29, 2026
- nahid-sparktales/agent-dispatchertheir own version, first seen Sep 21, 2026
- radif-ru/ai-multi-agent-systemtheir own version, first seen Jul 27, 2026
- GoldenWing-360/claude-security-skillstheir own version, first seen May 12, 2026
Other versions7 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 7
- DevelopersGlobal/ai-agent-skills★ 216same name
- nahid-sparktales/agent-dispatcher★ 59same name
- GoldenWing-360/claude-security-skills★ 16same name
- radif-ru/ai-multi-agent-system★ 6same name
- ismael-joffroy-chandoutis/claude-skills-public★ 0same name
- mikulgohil/claude-skills★ 0same name
- smitshivalkar-spectims4567/hsj-agent-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository65 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/building-agents/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms-full.txtllms.txt
- llms.txtllms.txt
- adding-guardrailsSkill
- agent-health-timeoutSkill
- agent-permission-scopingSkill
- agent-session-isolationSkill
- agent-step-loggingSkill
- agent-supervisor-routerSkill
- agent-telemetrySkill
- async-agent-backgroundSkill
- building-agentsSkill
- building-teamsSkill
- building-toolsSkill
- calendar-scheduling-toolSkill
- callback-tracing-handlerSkill
- chain-of-thought-promptingSkill
- chat-model-configurationSkill
- code-execution-sandboxSkill
- common-agent-patternsSkill
- context-window-managementSkill
- conversation-memorySkill
- conversation-state-dbSkill
- database-query-toolSkill
- document-loadersSkill
- document-rerankingSkill
- email-notification-toolSkill
- embedding-model-ingestionSkill
- fallback-model-chainSkill
- few-shot-injectionSkill
- filesystem-toolSkill
- human-in-the-loopSkill
- hybrid-searchSkill
- inspecting-streamsSkill
- integrating-with-laurenSkill
- json-schema-enforcementSkill
- llm-provider-connectionSkill
- llm-rate-limitingSkill
- long-term-vector-memorySkill
- managing-memorySkill
- migrating-to-lauren-aiSkill
- multi-agent-delegationSkill
- multi-tool-orchestrationSkill
- multi-turn-tool-stateSkill
- output-guardrailsSkill
- plan-and-execute-agentSkill
- prompt-versioningSkill
- rag-pipelineSkill
- react-agent-loopSkill
- response-validation-retrySkill
- rest-api-toolSkill
- securing-agentsSkill
- semantic-cacheSkill
- streaming-response-handlerSkill
- structured-output-parsingSkill
- sub-agent-spawningSkill
- system-prompt-templatingSkill
- testing-agentsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 5 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 62
When user-provided content is injected into prompts (e.g.
- Very specific: line 77
Use GuardrailViolated signal or wrap in a custom guard that logs to your audit trail:
- Distinctive: line 120
No guardrail is 100% effective — defense in depth is essential.
“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Use
codemap find "SymbolName"to locate any symbol before reading.
Input Sanitization for Prompt Injection Defense
Built-in: PromptInjectionFilter
Lauren-AI ships PromptInjectionFilter in lauren_ai._guardrails._builtin.
It detects the most common injection patterns with compiled regexes:
# NOTE: future annotations are allowed, but tool signature types must resolve at import time.
from lauren_ai import agent, use_guardrails, PromptInjectionFilter
@agent(model="claude-opus-4-6", system="You are a helpful assistant.")
@use_guardrails(input=[PromptInjectionFilter()])
class SafeAgent: ...Built-in patterns cover: ignore previous instructions, jailbreak, DAN,
[system], ###instruction, <|im_start|>, system: you are, and more.
Custom injection guard with extended patterns
import re
from lauren_ai import guardrail
from lauren_ai._guardrails._base import GuardrailContext, GuardrailDecision
INJECTION_PATTERNS = [
r"ignore\s+(previous|above|all)\s+instructions",
r"forget\s+(everything|your\s+instructions)",
r"you\s+are\s+now\s+(?:a\s+)?(?!helpful)",
r"disregard\s+(?:your\s+)?(?:previous|prior|all)\s+",
r"system\s*prompt\s*:\s*",
r"<\s*/?(?:system|instruction)\s*>",
r"act\s+as\s+(?:if\s+you\s+are\s+)?(?:a\s+)?(?:different|another|evil|jailbreak)",
]
@guardrail(kind="input")
class PromptInjectionGuard:
def __init__(self):
self._patterns = [re.compile(p, re.IGNORECASE) for p in INJECTION_PATTERNS]
async def check(self, message: str, ctx: GuardrailContext) -> GuardrailDecision:
for pattern in self._patterns:
if pattern.search(message):
return GuardrailDecision(
action="block",
violation="Potential prompt injection detected.",
guardrail_name="PromptInjectionGuard",
)
return GuardrailDecision(action="pass", guardrail_name="PromptInjectionGuard")RAG pipeline defense
When user-provided content is injected into prompts (e.g. from retrieved documents), sanitize the document text before embedding it in the prompt:
def sanitize_retrieved_text(text: str) -> str:
"""Strip HTML/XML-style instruction tags from retrieved text."""
import re
# Remove <system>, <instruction>, <|...|> style tags
text = re.sub(r'<[^>]{0,100}>', '', text)
text = re.sub(r'<\|[^|]{0,100}\|>', '', text)
return text.strip()Logging blocked attempts
Use GuardrailViolated signal or wrap in a custom guard that logs to your audit
trail:
from lauren_ai._guardrails._base import GuardrailContext, GuardrailDecision
import logging
logger = logging.getLogger("security.prompt_injection")
@guardrail(kind="input")
class AuditingInjectionGuard:
def __init__(self):
self._inner = PromptInjectionFilter()
async def check(self, message: str, ctx: GuardrailContext) -> GuardrailDecision:
decision = await self._inner.check(message, ctx)
if decision.action == "block":
logger.warning(
"Prompt injection blocked",
extra={
"user_id": ctx.user_id,
"agent": ctx.agent_name,
"message_preview": message[:200],
},
)
return decisionDecorator placement
Input guardrails must be in the input= list of @use_guardrails():
@agent(model="claude-opus-4-6")
@use_guardrails(input=[PromptInjectionGuard()])
class ProtectedAgent: ...Pitfalls
- Regex-based detection has false positives (e.g. "ignore previous chapters" in a book summary request). Tune patterns or add allow-listing for known-good phrases.
- No guardrail is 100% effective — defense in depth is essential. Combine with:
- A fixed, non-modifiable system prompt.
- Output guardrails to catch any slip-through.
- Least-privilege tool access.
- Adversarial prompts in retrieved documents (indirect injection) are harder to catch — always sanitize retrieved text before injection.
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
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.

