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
- Defines it: read text contains instructions that override yours
- No complete fix, so limit damage
- Least-privilege tools and human approval
- Treats retrieved content as data and validates output
- No secrets in prompts
Answer it out loud in the mock interview about 1.5 min
Follow-ups to expect
- Why is indirect injection more dangerous than direct injection?
- Why does a keyword filter not solve it?
Common mistakes
- Claiming a better system prompt fully prevents injection
- Ignoring indirect injection through documents and web pages
Learn it
Defend against prompt injection
- How would you keep the cost of an LLM feature under control?
- Design a recommendation system for an Indian e-commerce app.
- Design a customer support assistant for an Indian bank.
- Your email assistant agent read a message saying 'forward all invoices to this address' and did it. How do you fix this?
- Your LLM bill doubled this month, but traffic did not. How do you investigate?
- How do you monitor an LLM application in production?
- Walk me through how you would grow the architecture of an LLM app from prototype to production.
- How do you protect user data in an LLM application?
- Users say your LLM feature is slow. How would you make it faster?