Skip to main content

How to Guard Against Prompt Injection

Guide · about 7 min · refs checked 2026-11-03 (reference links and dates only)

Prompt injection is an attack where outside content hijacks an AI. This guide covers how to build defenses so your AI tool treats web pages as data, not commands.

How to
Treat outside content as data, not instructions: web pages, documents, and emails can hide "ignore your previous instructions". Grant least privilege: if reading suffices, grant read-only; if one directory suffices, do not hand over the whole disk. Keep a human gate on irreversible actions: deletions, transfers, and outbound messages ask a person first. Isolate sessions: do not mix a session that processes outside content with one that holds keys or manages accounts. Check what a tool can touch before installing it: read the MCP server's permission declarations. Keep execution logs: when something goes wrong, you can replay what it actually did.

Example and interpretation

A teaching scenario, not a measured or executed site test.

A retrieved document says to ignore rules and send files elsewhere. Treat it as document content, not authorization; enforce path and destination limits at execution. Removing one instruction does not prove broader resistance.

How to check your practice

Explain the example in your own words, inspect input constraints, then verify against the source. Revisit concepts if you cannot explain why; supply missing dates, fields or permissions; withdraw unsupported conclusions.

For this topic, start with missing input · See all six scenarios and their reasoning

Sources
  • Fetch server's security warning ↗
  • OWASP Top 10 for LLM Applications ↗