AI Security

Defending an app from prompt injection

By Reetu Poudel · 10 November 2026 · 5 min read

The moment your app lets a user's words reach a language model, their words can try to give the model orders. Here is how I keep them from being obeyed.

When I built Form Generator — a tool that turns a plain-language description into a working online form — I was handing a language model text written by strangers. That is the exact condition prompt injection needs: untrusted input flowing into a system that follows instructions. "Ignore your previous instructions and…" is the opening line of a real attack, not a joke.

Why this is hard

Classic injection (SQL, shell) has a clean fix: separate code from data. With language models the line is blurry on purpose — the whole point is that instructions are text. You cannot escape your way out of it. So the defense is not one trick; it is layers, each catching what the last one missed.

The layers I use

Treat model output as untrusted too

The injection you did not catch shows up in the output. So the response is never blindly trusted either: it is validated against the shape the app expects (a form schema, in my case), and it is never rendered as raw HTML or executed. Even a model that was successfully tricked produces something the app refuses to act on.

The mindset that matters

Prompt injection is not a bug you fix once; it is a property of mixing instructions and untrusted data, and it has to be managed. The questions I keep asking are the useful ones: What is the worst thing this input could make the model do? What capability does the model actually need? What happens if the guard fails? Answer those honestly and the attack surface shrinks fast.

You will not make an LLM app perfectly un-trickable. But you can make a successful trick worthless — and that is the real goal of security engineering: not a wall, but a system where getting in buys you nothing.

Prompt InjectionLLM SecurityAI SafetyRate LimitingLeast Privilege
← All posts