AI Engineering · LLM applications that ship

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

Hardsecurityprompt injectionuntrusted inputUpdated Oct 2026
Quiz this track

Short answer

Prompt injection is untrusted text persuading the model to ignore its instructions or misuse its tools. Defend with least privilege, data/instruction separation, output validation and human approval for risky actions.

Direct injection comes from the user; indirect injection hides in retrieved documents, web pages, emails or tool results. Both exploit the fact that a language model cannot perfectly distinguish instructions from data. If the model has tools, an injected instruction can become a real action.

  • Give the model the narrowest tool permissions and data access the task needs.
  • Keep secrets out of the prompt and never let model output alone authorise a payment, deletion or external message.
  • Mark untrusted spans clearly, validate outputs, and require confirmation for irreversible actions.
  • Log tool calls and inputs so an injection attempt is detectable after the fact.
No prompt wording makes injection impossible. Treat the model as an untrusted component and put the security boundary in your application.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1How is indirect injection different from a jailbreak?
  2. 2What would you log to investigate an injection incident?
  3. 3Why is least privilege more important than a stronger system prompt?

Say it in the interview

Prompt injection is any untrusted text that gets the model to follow attacker instructions instead of mine. The dangerous version is indirect, where it arrives inside a retrieved document and then triggers a tool call. I defend in layers: separate instructions from data, give tools minimal permissions, validate outputs, and require human approval for anything irreversible. I assume the prompt can be bypassed and enforce the real rules in code.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live AI Engineering mock interview and get scored feedback on depth, clarity and confidence.