ai-chat-protection

Validates and sanitizes AI chat prompts to block prompt injection, jailbreaks, and encoding attacks.

Updated Aug 8, 2026
One-click install
npx skills add https://github.com/harperaa/testa2 --skill ai-chat-protection-harperaa
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ai-chat-protection
Source: https://github.com/harperaa/testa2/tree/main/.claude/skills/security/ai-chat-protection
Command: npx skills add https://github.com/harperaa/testa2 --skill ai-chat-protection-harperaa

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? AI chatbots introduce a new attack surface where users can manipulate LLM behavior through prompt injection, jailbreak attempts, and encoding bypasses, potentially extracting system prompts, leaking other users' data, or causing cost explosions through token exhaustion. ## Core Features & Use Cases - Injection Pattern Blocking: Detects 49 regex patterns covering system prompt overrides, DAN-mode jailbreaks, SQL injection, command injection, and XSS payloads in chat input. - Encoding & DoS Defense: Blocks hex, unicode, and URL-encoded attacks, enforces special character ratio limits, and detects repetitive prompts designed for token exhaustion. - Server-Side Validation with Rate Limiting: The validatePromptServer function adds per-session request limits and suspicious-pattern logging for security monitoring. - Use Case: When building a Next.js API route that sends user messages to OpenAI or Anthropic, wrap the handler with validatePromptServer plus withRateLimit and withCsrf middleware so malicious prompts are rejected with HTTP 400 before ever reaching the LLM. ## Quick Start Use the ai-chat-protection skill to add prompt validation to my AI chat API route.

Frequently Asked Questions about ai-chat-protection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I protect an AI chatbot from prompt injection?

Validate every user message server-side with validatePromptServer before sending it to the LLM. It checks 49 injection patterns covering system prompt overrides, jailbreaks, and encoding attacks, returning a sanitized prompt only when validation succeeds.

How to validate LLM prompts in a Next.js API route?

Import validatePromptServer from lib/prompt-validation, call it with the message and user context inside your route handler, and return HTTP 400 on failure. Wrap the handler with withRateLimit and withCsrf middleware for layered protection.

What is the difference between validatePrompt and validatePromptServer?

validatePrompt performs basic validation of length, injection patterns, special characters, and repetition for client or simple server use. validatePromptServer adds rate limiting up to 100 requests per session and logs suspicious prompts containing words like admin, password, or token.

Does prompt validation block encoded injection attacks?

Yes, the validation detects hex, unicode, and URL-encoded payloads such as \x49\x67\x6e\x6f\x72\x65. It also rejects prompts where special characters exceed 30 percent of total length, which catches most obfuscated payloads.

Why is client-side prompt validation not enough for AI security?

Client-side validation only improves UX and can be bypassed by direct API calls. Attackers can send malicious payloads with curl, so the server must re-validate every prompt before it reaches the LLM.

How do I prevent AI chatbots from leaking other users' data?

Use policyPromptSchema, which blocks data access patterns like "show me all users" and "SELECT * FROM". Additionally, scope the AI context to only the authenticated user's own data fetched by their userId.