179 questions
No questions match those filters.
How do you handle prompt injection attacks in productio...
This is one of the questions in the full AI/ML interview bank. Pro unlocks all 1789 questions; Premium includes the same bank plus the highest daily Practice limit.
See plansPrompt injection comes in two flavors: direct, where a user explicitly tries to override the system prompt, and indirect, where malicious instructions are hidden inside a document, email, or web page the model reads as part of its context. Neither is fully solvable with a single defense, so production systems need layers: an upstream classifier that flags obviously malicious input before it even reaches the main prompt, wrapping all user-supplied content in delimiters with an explicit instruction to treat it as data rather than commands, and scanning the model’s output afterward for signs of a successful attack — leaked system-prompt text, off-topic content, competitor mentions.
Planting a canary string in the system prompt is a cheap but effective addition: if that exact string ever appears in a response, it’s unambiguous proof the system prompt leaked, and it’s a reliable trigger for an immediate security alert. None of these layers are individually airtight, so the last line of defense is limiting what damage a successful injection can actually do — giving the model read-only, narrowly scoped tool access so that even a compromised turn can’t do much harm.