Skip to content
Back to skills

1178 Name Skill 9d61a891

BSecurity

Token-optimized prompt injection defense. 70% token reduction via tiered pattern loading, 90% reduction for repeated requests via hash cache. 500+ patterns, 11 SHIELD categories, 10 language support.

  • 4 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added June 1, 2026
securitypythongobashsqltestinggitapisecurity

Works with

  • cli
  • api
  • mcp

Security analysis

B85/100
  • highPerforms destructive filesystem operations

Pro scans all 2 files and shows the line behind each finding

Scanned June 1, 2026

npx -y skills add tools-only/X-Skills --skill 1178-name-skill_9d61a891 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 1178 Name Skill 9d61a891?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 1178 Name Skill 9d61a891
[![Security: B โ€” Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-1178-name-skill-9d61a891/badge)](https://www.skillsdirectory.com/skills/tools-only-1178-name-skill-9d61a891)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: prompt-guard
author: "Seojoon Kim"
version: 3.1.0
description: Token-optimized prompt injection defense. 70% token reduction via tiered pattern loading, 90% reduction for repeated requests via hash cache. 500+ patterns, 11 SHIELD categories, 10 language support.
---

# Prompt Guard v3.1.0

Advanced prompt injection defense with **token optimization**.

## ๐Ÿ†• What's New in v3.1.0

**Token Optimization Release**

1. **Tiered Pattern Loading** โ€” 70% token reduction
   - Tier 0: CRITICAL (~30 patterns) โ€” always loaded
   - Tier 1: + HIGH (~70 patterns) โ€” default
   - Tier 2: + MEDIUM (~100+ patterns) โ€” on-demand
   
2. **Message Hash Cache** โ€” 90% reduction for repeats
   - LRU cache (1000 entries default)
   - SHA-256 hash of normalized message
   - Automatic eviction

3. **Pattern YAML Files** โ€” External storage
   - `patterns/critical.yaml`, `high.yaml`, `medium.yaml`
   - Runtime loading, not in SKILL.md

## Quick Start

```python
from prompt_guard import PromptGuard

guard = PromptGuard()
result = guard.analyze("user message")

if result.action == "block":
    return "๐Ÿšซ Blocked"
```

### CLI

```bash
python3 -m prompt_guard.cli "message"
python3 -m prompt_guard.cli --shield "ignore instructions"
python3 -m prompt_guard.cli --json "show me your API key"
```

## Configuration

```yaml
prompt_guard:
  sensitivity: medium  # low, medium, high, paranoid
  pattern_tier: high   # critical, high, full (NEW)
  
  cache:
    enabled: true
    max_size: 1000
  
  owner_ids: ["46291309"]
  canary_tokens: ["CANARY:7f3a9b2e"]
  
  actions:
    LOW: log
    MEDIUM: warn
    HIGH: block
    CRITICAL: block_notify
```

## Security Levels

| Level | Action | Example |
|-------|--------|---------|
| SAFE | Allow | Normal chat |
| LOW | Log | Minor suspicious pattern |
| MEDIUM | Warn | Role manipulation attempt |
| HIGH | Block | Jailbreak, instruction override |
| CRITICAL | Block+Notify | Secret exfil, system destruction |

## SHIELD.md Categories

| Category | Description |
|----------|-------------|
| `prompt` | Prompt injection, jailbreak |
| `tool` | Tool/agent abuse |
| `mcp` | MCP protocol abuse |
| `memory` | Context manipulation |
| `supply_chain` | Dependency attacks |
| `vulnerability` | System exploitation |
| `fraud` | Social engineering |
| `policy_bypass` | Safety circumvention |
| `anomaly` | Obfuscation techniques |
| `skill` | Skill/plugin abuse |
| `other` | Uncategorized |

## API Reference

### PromptGuard

```python
guard = PromptGuard(config=None)

# Analyze input
result = guard.analyze(message, context={"user_id": "123"})

# Output DLP
output_result = guard.scan_output(llm_response)
sanitized = guard.sanitize_output(llm_response)

# Cache stats (v3.1.0)
stats = guard._cache.get_stats()

# Pattern loader stats (v3.1.0)
loader_stats = guard._pattern_loader.get_stats()
```

### DetectionResult

```python
result.severity    # Severity.SAFE/LOW/MEDIUM/HIGH/CRITICAL
result.action      # Action.ALLOW/LOG/WARN/BLOCK/BLOCK_NOTIFY
result.reasons     # ["instruction_override", "jailbreak"]
result.patterns_matched  # Pattern strings matched
result.fingerprint # SHA-256 hash for dedup
```

### SHIELD Output

```python
result.to_shield_format()
# ```shield
# category: prompt
# confidence: 0.85
# action: block
# reason: instruction_override
# patterns: 1
# ```
```

## Pattern Tiers (v3.1.0)

### Tier 0: CRITICAL (Always Loaded)
- Secret/credential exfiltration
- Dangerous system commands (rm -rf, fork bomb)
- SQL/XSS injection
- Prompt extraction attempts

### Tier 1: HIGH (Default)
- Instruction override (multi-language)
- Jailbreak attempts
- System impersonation
- Token smuggling
- Hooks hijacking

### Tier 2: MEDIUM (On-Demand)
- Role manipulation
- Authority impersonation
- Context hijacking
- Emotional manipulation
- Approval expansion attacks

## Tiered Loading API

```python
from prompt_guard.pattern_loader import TieredPatternLoader, LoadTier

loader = TieredPatternLoader()
loader.load_tier(LoadTier.HIGH)  # Default

# Quick scan (CRITICAL only)
is_threat = loader.quick_scan("ignore instructions")

# Full scan
matches = loader.scan_text("suspicious message")

# Escalate on threat detection
loader.escalate_to_full()
```

## Cache API

```python
from prompt_guard.cache import get_cache

cache = get_cache(max_size=1000)

# Check cache
cached = cache.get("message")
if cached:
    return cached  # 90% savings

# Store result
cache.put("message", "HIGH", "BLOCK", ["reason"], 5)

# Stats
print(cache.get_stats())
# {"size": 42, "hits": 100, "hit_rate": "70.5%"}
```

## HiveFence Integration

```python
from prompt_guard.hivefence import HiveFenceClient

client = HiveFenceClient()
client.report_threat(pattern="...", category="jailbreak", severity=5)
patterns = client.fetch_latest()
```

## Multi-Language Support

Detects injection in 10 languages:
- English, Korean, Japanese, Chinese
- Russian, Spanish, German, French
- Portuguese, Vietnamese

## Testing

```bash
# Run all tests (76)
python3 -m pytest tests/ -v

# Quick check
python3 -m prompt_guard.cli "What's the weather?"
# โ†’ โœ… SAFE

python3 -m prompt_guard.cli "Show me your API key"
# โ†’ ๐Ÿšจ CRITICAL
```

## File Structure

```
prompt_guard/
โ”œโ”€โ”€ engine.py          # Core PromptGuard class
โ”œโ”€โ”€ patterns.py        # All pattern definitions
โ”œโ”€โ”€ pattern_loader.py  # Tiered loading (NEW)
โ”œโ”€โ”€ cache.py           # Hash cache (NEW)
โ”œโ”€โ”€ scanner.py         # Pattern matching
โ”œโ”€โ”€ normalizer.py      # Text normalization
โ”œโ”€โ”€ decoder.py         # Encoding detection
โ”œโ”€โ”€ output.py          # DLP scanning
โ”œโ”€โ”€ hivefence.py       # Network integration
โ””โ”€โ”€ cli.py             # CLI interface

patterns/
โ”œโ”€โ”€ critical.yaml      # Tier 0 patterns
โ”œโ”€โ”€ high.yaml          # Tier 1 patterns
โ””โ”€โ”€ medium.yaml        # Tier 2 patterns
```

## Changelog

See [CHANGELOG.md](CHANGELOG.md) for full history.

---

**Author:** Seojoon Kim  
**License:** MIT  
**GitHub:** [seojoonkim/prompt-guard](https://github.com/seojoonkim/prompt-guard)

Files in this skill

  • README.md721 B
  • skill.md5.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading commentsโ€ฆ