Prompt Injection Defense logo

Prompt Injection Defense

Community
seb1n
prompt-injection-defense

Threat-model and harden AI agents, RAG systems, assistants, and tool-using workflows against direct, indirect, stored, cross-agent, and multimodal prompt injection. Use when reviewing an agent architecture, isolating untrusted content, constraining tools and egress, protecting secrets, adding injection-focused tests, investigating a suspected injection incident, or documenting residual prompt-injection risk.

Overview

Publisherseb1n
Repositoryawesome-ai-agent-skills
Skill nameprompt-injection-defense
Stars
188
Forks
35
Bundled files
3
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 3 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by seb1n on GitHub. Read the source before you install it.

Installation

Install the Prompt Injection Defense AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/seb1n/awesome-ai-agent-skills.git /tmp/awesome-ai-agent-skills
mkdir -p .claude/skills
cp -r /tmp/awesome-ai-agent-skills/agent-security/prompt-injection-defense .claude/skills/prompt-injection-defense
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Prompt Injection Defense in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Prompt Injection Defense on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Prompt Injection Defense is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Prompt Injection Defense

Design for compromise of model reasoning. Prompt text and classifiers can reduce attack success, but they do not create a reliable security boundary. Keep consequential authority, authorization, validation, and policy enforcement outside the model.

Inputs

Collect or infer, and label assumptions for:

  • Agent purpose, system/developer instructions, models, memory, and orchestration
  • Every input source, including users, web pages, email, documents, images, audio, tool results, RAG, and other agents
  • Tool list, privileges, identities, targets, write effects, and network egress
  • Secrets, private data, system prompts, policy data, and other protected assets
  • Output sinks such as UI rendering, code execution, messages, databases, and downstream agents
  • Authorization model, human gates, monitoring, incident history, and risk tolerance
  • Representative benign tasks and a safe evaluation environment

Do not request production secrets or malicious artifacts in chat. Use redacted samples or synthetic fixtures.

Output contract

Deliver:

  1. A data-flow and trust-boundary map covering protected assets, all modalities, sinks, memory stores, agent hops, approved destinations, and credential boundaries
  2. A threat model listing protected assets, attacker-controlled channels, injection paths, and security invariants
  3. A prioritized defense plan that maps each path to preventive, limiting, detective, and recovery controls, each marked missing, planned, implemented, or verified
  4. Code or configuration changes only within the user's authorized scope
  5. A regression suite with safe direct, indirect, stored, encoded, cross-agent, and multimodal cases as applicable
  6. Verification evidence, observed failures, and metrics rather than a blanket claim of prevention
  7. Residual risk, operational monitoring, and an incident containment/recovery plan

Describe the architecture in a JSON boundary manifest and lint it with scripts/audit_boundary_manifest.py. Record every control's enforcement point, owner, evidence IDs, test IDs, and expiry when time-limited. A passing structural lint is not evidence that controls work. Read references/defense-patterns.md for attack paths, control placement, and verification patterns.

Workflow

1. Map instructions, data, authority, and sinks

Trace content from origin through parsing, retrieval, model context, memory, tools, renderers, output sinks, and downstream agents. Mark every attacker-controlled or mixed-trust source. Include hidden document text, metadata, code comments, OCR, images, audio, redirects, tool descriptions, and persisted memory. Inventory approved and denied destinations, each credential's holder/audience/storage boundary, and every point where content or authority crosses agents.

List assets and consequences: secret disclosure, private-data access, unauthorized tool calls, external communications, transactions, code execution, policy bypass, corrupted memory, or misleading output.

2. Define enforceable invariants

Express requirements in terms a deterministic component can enforce, for example:

  • Retrieved content cannot grant permissions or change the tool allowlist.
  • A support agent cannot read records outside the authenticated tenant.
  • An email body cannot determine recipients for a send operation.
  • Model output cannot execute as code or HTML without validation and safe handling.
  • Secrets unavailable to the task never enter model context.

If an invariant exists only as a prompt instruction, record it as weak and move enforcement to code, policy, isolation, or human control.

3. Reduce exposed authority

Remove unused tools, broad tokens, ambient credentials, generic shells, arbitrary URL fetches, raw SQL, and unrestricted file access. Split read from write and preview from commit. Restrict identities by tenant, object, action, fields, time, and destination.

Keep secrets outside model context and tool results. Add network and data egress allowlists. Sandbox code, parsers, browsers, and file processing. Require independent authorization and, where warranted, action-specific approval immediately before consequential effects. A tool classified critical must not have confirmation mode none.

4. Separate control from untrusted content

Treat untrusted content as quoted data with provenance, never as authority. Preserve source boundaries through retrieval and agent handoffs. Use structured typed messages instead of concatenating instructions and data. Limit retrieved content, strip active content when safe, normalize supported formats, and render outputs with context-appropriate escaping.

Instruction hierarchy, delimiters, reminders, content classifiers, and injection detectors can be defense-in-depth signals. Do not depend on any of them as the sole control.

5. Validate every transition

Validate tool arguments against narrow schemas and policy before execution. Derive sensitive target identifiers from trusted application state rather than untrusted text where possible. Reauthorize at execution time. Validate and encode model outputs for their destination; never send them directly to shells, SQL, templates, URLs, or privileged APIs.

For multi-agent systems, authenticate senders, constrain delegation depth and budgets, pass structured claims with provenance, and recalculate permissions at each hop. Never inherit the broadest upstream privilege implicitly.

6. Test with safe adversarial cases

Use an isolated environment, synthetic accounts, benign canary secrets, inert destinations, and non-destructive tools. Test at least:

  • Direct attempts to override instructions or elicit protected data
  • Indirect instructions embedded in retrieved pages, email, documents, tool results, metadata, and memory
  • Obfuscation, encoding, language changes, splitting across turns, and repeated attempts
  • Cross-agent delegation and tainted summaries
  • Hidden or alternate-modal content when images, audio, PDFs, HTML, or OCR are supported
  • Tool-argument manipulation, target substitution, data exfiltration, and unauthorized egress
  • False positives on representative benign content and normal task completion

Measure invariant violations, unauthorized tool attempts, canary exposure, successful benign tasks, false-positive rate, and containment behavior. A detector pass rate alone is insufficient. Promote a control to verified only when implementation evidence and named test evidence both exist; use implemented when code exists but the relevant tests have not established behavior.

7. Operate and recover

Log provenance, policy decisions, tool/target metadata, denials, and anomalous sequences without storing secrets or unnecessary content. Alert on canary access, repeated policy failures, new tool exposure, cross-tenant attempts, and unexpected egress.

For a suspected incident, stop or isolate the affected workflow, disable high-risk tools and egress, revoke or rotate exposed credentials, quarantine malicious sources, preserve redacted evidence, identify persisted memory/vector entries and downstream effects, restore clean state, and rerun regression tests before re-enabling access.

Authorization and safety boundaries

  • Do not test payloads against production, third-party, or user systems without explicit target-specific authorization.
  • Do not trigger real transactions, messages, deletions, access changes, malware, or data exfiltration; use inert canaries and synthetic destinations.
  • Never place real secrets, personal data, privileged system prompts, or live tokens in test corpora or logs.
  • Do not claim that prompt injection has been eliminated. State tested scope, model/configuration, evidence, limitations, and residual risk.
  • Do not silently delete potentially compromised memory, records, or evidence; quarantine first and follow the owner's retention and incident policy.
  • Stop testing and escalate if scope is uncertain, a canary reaches an unintended system, real sensitive data appears, or an unexpected external effect occurs.

Verification and recovery

Before completion, confirm that every protected asset, untrusted path, sink, memory store, agent hop, destination, and credential boundary is represented; every consequential effect has a non-model authority check; critical tools have confirmation; exposed privileges are minimized; and regression tests exercise both attack resistance and benign-task utility. Do not turn unknowns into unsupported all-true assertions: retain missing and planned controls as visible gaps. Re-run tests after model, prompt, parser, retrieval, tool, permission, or orchestration changes.

If a control causes unacceptable task failure, roll back that control in isolation, keep higher-risk tools disabled, preserve the failing case, and redesign the boundary. Do not restore broad authority simply to improve the success rate.

Realistic examples

Email triage agent

Treat subjects, bodies, attachments, and quoted threads as untrusted data. Let the model classify and draft, but derive mailbox and tenant from authenticated state. Separate draft from send, restrict recipient domains, require exact-message approval for external sends, and test an attachment containing an inert instruction to reveal a canary or change the recipient.

Research agent with web access

Run browsing with no access to internal secrets. Allowlist required destinations, strip active content, retain page provenance, and prevent page text from expanding tools or changing the research goal. Test hidden page text, a malicious tool result, encoded instructions, and a normal page containing security-related phrases to measure false positives.

Completion check

Finish only when architecture, controls, tests, and recovery cover the full data flow; evidence shows protected invariants hold in the tested environment; benign utility remains measured; and residual risk plus unverified surfaces are explicit.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Prompt Injection Defense AI skill do?

Threat-model and harden AI agents, RAG systems, assistants, and tool-using workflows against direct, indirect, stored, cross-agent, and multimodal prompt injection. Use when reviewing an agent architecture, isolating untrusted content, constraining tools and egress, protecting secrets, adding injection-focused tests, investigating a suspected injection incident, or documenting residual prompt-injection risk.

Why use Prompt Injection Defense on TypingMind?

Because you install it once and use it with any model. Prompt Injection Defense is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Prompt Injection Defense in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/seb1n/awesome-ai-agent-skills/tree/main/agent-security/prompt-injection-defense. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Prompt Injection Defense?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Prompt Injection Defense?

As many as you like. As long as a model supports skills, you can use Prompt Injection Defense with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Prompt Injection Defense AI skill free?

Yes. It is published on GitHub by seb1n under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇