AI EngineeringAdvanced15 min

Guardrails & prompt injection

Defend systems where untrusted text can steer a model that holds real permissions.

See it on the map

Prompt injection happens when text the model reads, such as a web page, an email or a document, contains instructions that the model follows as if the user had given them. It is not fully preventable by wording, so design as though it will sometimes succeed.

The strongest defence is limiting what a hijacked model can do. Separate untrusted content from privileged actions, give agents least privilege, and require confirmation before sending data out or making changes. An agent that can read private data, read untrusted content and communicate externally has all three ingredients of a data leak.

Add layers around that: validate and constrain outputs, filter obviously unsafe content, rate limit tool use, and log enough to investigate. Test with adversarial cases in your evals, not once before launch.

Key points

  • Assume injection will sometimes work and limit the blast radius.
  • Avoid combining private data, untrusted input and outbound channels in one agent.
  • Confirm irreversible or data-leaving actions with a human.
  • Keep adversarial cases in your eval suite.

Answer these out loud

  1. 1An email-summarising agent can also send email. Describe an attack and two design changes that stop it.
  2. 2Which of your tools would you make read-only or approval-gated first?

Use this from an agent

Any MCP client, including Grok, can read this lesson. See how to connect.

REST
curl https://engineeros-delta.vercel.app/api/v1/topics/guardrails-and-prompt-injection