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
- A Prompt Guard at the door. Before user text ever reaches the model as an instruction, it is screened for known injection patterns and intent. Suspicious input is rejected or defanged, not forwarded.
- A trained Prompt Router. Not every request should take the same path. A router — trained on the kinds of requests the app actually serves — decides what a message is allowed to do, so a "form description" cannot quietly become a "system command".
- Least privilege for the model. The model only ever gets the capability the task needs. If it cannot reach a database, delete a record, or call an external tool, an injected instruction to do so has nothing to grab.
- Rate limiting and monitoring. Attacks are iterative — people probe. Per-user rate limits slow that down, and logging the attempts tells you what new patterns to guard against.
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.
← All posts