Skip to main content

What is prompt injection, and how do you defend against it?

System design · Pro 1

Short answer

Prompt injection is when text the model reads, from a user or from a document, web page or email, contains instructions that override yours. There is no complete fix, so design to limit damage: least-privilege tools, human approval for risky actions, treat retrieved content as data, validate outputs, and never put secrets in prompts.

Deeper answer

Direct injection comes from the user typing it. Indirect injection is hidden in content the app processes, which is more dangerous because the user may be the victim. It tops the OWASP list for LLM applications.

Defences in layers: keep sensitive actions outside the model's reach or behind confirmation; enforce permissions in code, not instructions; separate untrusted content clearly in the prompt; filter and validate outputs before acting; monitor for unusual tool use. Detection classifiers help but can be bypassed, so they are not the only control.

What a strong answer covers

Answer it out loud in the mock interview about 1.5 min

Follow-ups to expect

Common mistakes

Learn it

Defend against prompt injection

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.