मुख्य सामग्री पर जाएँ
Skillpedia
एजेंट48k · #5528

prompt-injection-defense

यह क्या करती है

यह टूल AI सिस्टम को 'prompt injection' नाम के खतरनाक हमलों से बचाता है, जिसमें कोई AI पर कब्जा करने की कोशिश करता है। यह इनपुट की जाँच करता है, AI क्या-क्या कर सकता है उसे सीमित करता है, और AI के जवाबों को भी परखता है।

कब इस्तेमाल करें

  • ✓AI से चलने वाली ऐप्स बनाते या सुरक्षित करते समय।
  • ✓जब AI के साथ ऐसे दस्तावेज़ इस्तेमाल करने हों जिनका स्रोत भरोसेमंद न हो।
  • ✓जब AI को दूसरे tools या functions इस्तेमाल करने देने हों।

Skill का लिंक

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/prompt-injection-defense/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/prompt-injection-defense/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“इस application को text में छिपे खतरनाक निर्देशों से बचाओ।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

टूल AI को मिलने वाले text में खतरनाक कमांड की जाँच करता है। यह AI द्वारा किए जा सकने वाले कामों को भी सीमित करता है और यह पक्का करता है कि उसके जवाब सुरक्षित हों।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Prompt Injection Defense

Mitigate direct and indirect prompt injection across chat apps, agentic workflows, and RAG pipelines.

When to Use This Skill

Use this skill when:

  • Building or securing any LLM-powered application
  • Designing RAG pipelines that ingest untrusted documents
  • Implementing agentic workflows with tool-calling capabilities
  • Responding to a reported prompt injection vulnerability
  • Performing security reviews of AI-integrated products

Prerequisites

  • Python 3.10+ with re, hashlib, json standard libraries
  • Access to the LLM application source code or configuration
  • Understanding of the application's prompt architecture (system/user/tool boundaries)
  • Test environment with representative user inputs and documents

Attack Surface

  • User input attempting to override system instructions
  • Untrusted documents/web pages in retrieval context
  • Tool output that smuggles malicious instructions
  • Cross-tenant leakage via shared context windows
  • Markdown or HTML injection in rendered outputs
  • Multi-turn attacks that gradually shift context

Defense-in-Depth Pattern

  1. Instruction hierarchy enforcement: system > developer > user > tool output.
  2. Context segregation: isolate untrusted text from control instructions.
  3. Tool permissioning: explicit allow-list per task and tenant.
  4. Output policy checks: validate schema, redact secrets, block unsafe actions.
  5. Human approval: required for high-impact operations.

Input Sanitization Functions

"""prompt_sanitizer.py - Input sanitization for LLM applications."""

import re
import hashlib
import json
from typing import Optional

# Patterns that commonly appear in injection attempts
INJECTION_PATTERNS = [
    r"(?i)ignore\s+(all\s+)?previous\s+instructions",
    r"(?i)disregard\s+(all\s+)?(above|previous|prior)",
    r"(?i)you\s+are\s+now\s+(DAN|evil|unrestricted|jailbroken)",
    r"(?i)system\s*:\s*override",
    r"(?i)SYSTEM\s+OVERRIDE",
    r"(?i)new\s+instructions?\s*:",
    r"(?i)forget\s+(everything|all|your\s+instructions)",
    r"(?i)act\s+as\s+if\s+you\s+have\s+no\s+(restrictions|limits|rules)",
    r"(?i)pretend\s+(you\s+are|to\s+be)\s+.*(unrestricted|evil|without)",
    r"(?i)BEGIN\s+(TRUSTED|SYSTEM|ADMIN)\s+(CONTEXT|PROMPT|OVERRIDE)",
    r"(?i)```system",
    r"(?i)\[INST\]",
    r"(?i)<\|im_start\|>system",
]

COMPILED_PATTERNS = [re.compile(p) for p in INJECTION_PATTERNS]


def detect_injection(text: str) -> dict:
    """Scan text for known prompt injection patterns.

    Returns:
        dict with 'detected' bool, 'patterns' list of matched pattern descriptions,
        and 'risk_score' float between 0.0 and 1.0.
    """
    matches = []
    for i, pattern in enumerate(COMPILED_PATTERNS):
        if pattern.search(text):
            matches.append(INJECTION_PATTERNS[i])

    risk_score = min(len(matches) / 3.0, 1.0)
    return {
        "detected": len(matches) > 0,
        "patterns": matches,
        "risk_score": risk_score,
        "input_length": len(text),
    }


def sanitize_input(text: str, max_length: int = 4096) -> str:
    """Sanitize user input before passing to the LLM.

    - Truncates to max_length
    - Strips null bytes and control characters
    - Removes Unicode homoglyph tricks
    - Normalizes whitespace
    """
    # Truncate
    text = text[:max_length]

    # Remove null bytes and most control characters (keep newlines and tabs)
    text = re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]', '', text)

    # Normalize Unicode confusables (basic set)
    confusable_map = {
        '\u200b': '',   # zero-width space
        '\u200c': '',   # zero-width non-joiner
        '\u200d': '',   # zero-width joiner
        '\u2060': '',   # word joiner
        '\ufeff': '',   # BOM
        '\u00a0': ' ',  # non-breaking space
    }
    for char, replacement in confusable_map.items():
        text = text.replace(char, replacement)

    # Collapse excessive whitespace
    text = re.sub(r'\n{4,}', '\n\n\n', text)
    text = re.sub(r' {10,}', '     ', text)

    return text.strip()


def sanitize_retrieved_context(documents: list[str], source_label: str = "RETRIEVED") -> str:
    """Wrap retrieved documents with clear boundary markers.

    This makes it harder for injected instructions in documents
    to be interpreted as system or user messages.
    """
    sanitized_parts = []
    for i, doc in enumerate(documents):
        doc_hash = hashlib.sha256(doc.encode()).hexdigest()[:8]

…
अक्सर पूछे जाने वाले सवाल

'prompt injection' क्या है?

यह तब होता है जब कोई AI को धोखा देकर उसके असली निर्देशों की जगह छिपे या गलत निर्देश मानने पर मजबूर करता है।

इसकी चिंता क्यों करनी चाहिए?

Prompt injection से AI जानकारी लीक कर सकता है, ऐसे काम कर सकता है जो आप नहीं चाहते, या असुरक्षित तरीके से व्यवहार कर सकता है।

यह टूल कैसे मदद करता है?

यह एक सिक्योरिटी गार्ड की तरह काम करता है, जो AI के इनपुट और आउटपुट की जाँच करता है ताकि खतरनाक कमांड चलने से पहले ही रोक दिए जाएँ।

जानकारी

लेखक का मूल विवरण

Defend AI systems against prompt injection and indirect prompt attacks using input controls, tool permissions, output validation, and isolation boundaries.

repo: sickn33/agentic-awesome-skills

लोकप्रियता

GitHub स्टार
48k
रैंकिंग में स्थान
#5528
लाइसेंस
MIT
अपडेट की गई
15/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

00-andruia-consultant

48k

आपके एजेंट को AI प्रोजेक्ट शुरू करने या उन्हें बेहतर बनाने में मदद करता है। यह code का विश्लेषण करता है, tools सुझाता है और स्पेनिश भाषा में action plan बनाता है।

AI और एजेंटएजेंट

007

48k

आपका एजेंट security audit और threat modeling करता है। यह प्रोजेक्ट को हमलों और कमजोरियों से बचाने में काम आता है।

कोडिंगसिक्योरिटी

10-andruia-skill-smith

48k

आपके एजेंट को AI tools बनाने या उन्हें बेहतर करने में मदद करता है। यह तय करता है कि tools कैसे काम करेंगे, documentation लिखता है और structure की जांच करता है।

AI और एजेंटएजेंट

20-andruia-niche-intelligence

48k

आपका एजेंट किसी खास industry का summary बनाता है। भरोसेमंद स्रोतों की मदद से यह प्रोजेक्ट का संदर्भ, नियम, इस्तेमाल के तरीके और जोखिम समझने में मदद करता है।

लेखन और डॉक्यूमेंटरिसर्च

मिलती-जुलती skills