- Group attacks by where they land. Data, input, instructions, tools and spend each need a different control, and a control for one family does nothing for the next.
- Do not rely on the model to police itself. Injection defences that ask the model to behave are the easiest layer to talk past. The layers I rely on sit in ordinary code around it.
- Authorization belongs to the host. An agent should reach a tool only after code outside the model has allowed the call.
- Model output is untrusted input. Everything a model returns passes a schema, a check against the source and the same validation a person's edit would pass.
- Evaluation decides what ships. A benchmark built from the real task beats intuition about which model, framework or retrieval method is better.
Most lists of AI attacks are long and flat: jailbreaks, poisoning, adversarial examples, prompt leaking, model theft. I find it more useful to ask first where the attacker acts. The answer gives five families, and each one points at a different place to put a control.
The figure follows an AI system from its training data to the bill it runs up. Under each point is the family of attack that acts there.
The first two families are classic adversarial machine learning. The last three appeared once models started reading untrusted text and calling tools. After the five families, I cover what shipping AI features has taught me about model output, deployment and evaluation.
The table pairs each family with the work behind it. Read the last column first: it names the control I use.
| Family | Where the attacker acts | What I built or broke | The control I use |
|---|---|---|---|
| Poisoned data | The training set | A bagging defence against label flipping, published at PST 2025 | Weights that come from the data itself |
| Perturbed input | One input at inference time | FGSM and PGD attacks on a fine-tuned face model | Treat a single prediction as evidence only |
| Injected instructions | Text the model reads | Layered input and output checks on a grounded assistant | Code around the model, with grounding doing the real work |
| Overreaching tools | What an agent can reach | Permission controls and an MCP client in a shipping agent app | The host decides, before the call runs |
| Runaway spend | The bill | Rate limits and a daily token budget that acts as a kill switch | Hard ceilings in config |
My MSc focus is networking and IT security, and I hold Security+ and ISC2 CC. So I came to the newer families from the network side: find the trust boundary, then ask who controls each side of it.
In a poisoning attack the attacker never touches the model. They change what it learns from. Label flipping is the plainest version: relabel some training samples so the model learns the wrong mapping.
Bagging already blunts this. Each model in the ensemble sees a different bootstrap sample, so no single poisoned sample reaches every model. Weighted bagging goes further and makes suspicious samples less likely to be drawn. The trouble is that the weights are usually hand-tuned and unstable.
With co-authors at Ontario Tech, I made the weights come from the data. One small autoencoder per class learns what clean samples of that class look like. A new sample that its own class's autoencoder reconstructs badly gets a high suspicion score, and the score sets its chance of being drawn.
Under 50% label flipping on MNIST, the best weighted ensemble reached 98.06% accuracy. The best standard bagging ensemble reached 97.67%, and a single CNN 97.04%. More than 24,000 samples got a drawing probability of zero.
Every poisoning defence I have seen trades a little clean accuracy for protection. The useful question is how much poisoning you expect.
The second family attacks one input at a time. On a course project, my team fine-tuned a FaceNet model on photos of ourselves. It turns a face into a 512-number embedding and predicts whoever's training embedding is nearest.
We built a demo that attacks it with FGSM, one step along the sign of the gradient. It also runs PGD, which repeats that step and keeps the change inside a small bound. The noise is faint to a person, but it can push the embedding over the line to someone else's identity.
That changed how I read any classifier sitting in front of a decision. A nearest-neighbour rule has a hard edge, and an attacker who can query the model can find it. So I treat a single prediction as evidence. When a wrong answer matters, the output should be one input to a decision that also checks something the attacker cannot perturb.
Prompt injection is the family I meet most at work. A model that reads a web page, an email or a retrieved document reads any instructions an attacker hid in it. It has no reliable way to tell the attacker's instructions from mine.
I built a grounded assistant for this site to work through the problem. It is built and tested, not yet live on this site. Its input checks run cheapest first: a length limit, a coarse pattern filter, redaction of emails and phone numbers, then a small classifier. The classifier labels each message on-topic, off-topic, harmful or injection.11 The answer is also checked as it streams, so a leaked phrase split across two chunks still stops the stream.
None of those layers is the boundary. The pattern filter is a spam filter, and the classifier fails open during an outage. What carries the weight is grounding: the assistant answers only from retrieved pages, and the system prompt treats that text as reference data, never as instructions.
Asking the model to ignore injected instructions helps, but an attacker can often talk past it. The layers I rely on are ordinary code that limits what the model sees and what its output can do.
Once an agent can call tools, an injected instruction stops being embarrassing and starts being dangerous. The question becomes what the agent can reach, and who decided.
Model Context Protocol (MCP) servers make this concrete. An agent calls tools on servers it did not write, so the server's authentication and authorization form the trust boundary between the model and real systems.
I mapped the known MCP threats onto a server's life. At creation, the risks are name collision, spoofed installers and backdoors. In operation, they are tool name conflicts and sandbox escape. After an update, they are stale privilege that should have been revoked, vulnerable versions and configuration drift. That last group is the easiest to miss, because nothing looks wrong on the day it happens.
In the AI coding desktop app I work on, I designed the controls that decide what the agent may do. A tool call runs only once it is permitted. Each permission mode allows a set list of actions, and scheduled runs that nobody is watching get stricter limits of their own.
I built the MCP client the agents use. It signs in to protected servers with OAuth 2.1 and PKCE, supports all three transports and reconnects when a server drops.
Both controls run in the host, outside the model, so an instruction injected into the conversation cannot widen what the agent may do.
The fifth family is the least glamorous. An attacker who cannot steal data can still make you pay: a script that sends a public endpoint a few thousand messages costs real money in tokens.
The grounded assistant gives each client 15 messages a minute and 200 a day. A daily budget of 3,000,000 tokens and an environment flag both act as a kill switch that returns a plain 503. I prefer a ceiling in config to an alert in a dashboard, because it acts when nobody is watching.
The same habits carry over from attacks to the AI features I have shipped. Whatever a model returns is input from a stranger, and a test built from the real task settles what ships.
At work I shipped an assistant that proposes edits for a person to approve. Each approved edit passes the same validation and access checks as a manual edit. A voice agent fills the same form as a person talks, and code checks every spoken answer before it is saved.
I also moved LLM document parsing to production. Its output must match a schema, and each extracted value must appear in the source document.
I handle a model the way I would handle any unreliable upstream service: my code checks what it returns before acting on it.
Not every model needs a frontier API. In Reelkit, a video editor that models drive over MCP, two small open models run on llama-server on a laptop GPU with 6 GB of memory. They are Qwen3.5-4B and Qwen3.5-9B.
After the fixes the first benchmark run surfaced, they passed 95.2% and 94.2% of the edit checks across 150 challenges on real NASA footage. Most of those fixes went to the tools and their descriptions, and the models stayed the same.
Deployment taught me its own lessons, usually the hard way:
- Pin what holds state. This site's API runs in Docker on AWS and deploys on every push. One deploy returned 502 for every request because
postgres:latesthad moved to a new major version that could not read the existing data volume. Pinning the database image to the version that wrote the data fixed it. Anything that owns data on disk gets a pinned version. - Do expensive work once. The recommender in an online store where I built the backend is trained once at startup and cached, so a product page never waits on it.
- Isolate awkward dependencies. The assistant's Google SDK clashed with the main Django image, so it runs in its own small container on the internal network.
Most arguments about which model or framework is better end when someone builds a test from the real task. I have built several.
- Frameworks. I built one clinic intake agent five times, in five agent frameworks, on one MCP server, one prompt and one mechanical scorer over 55 patient messages. Accuracy did not separate them. What reached the model, and one framework's cost, did.
- Retrieval. At work I compared keyword, semantic and hybrid search on real queries, and the measured results settled the choice.
- Generated files. I scored Office and PDF skills on the files models actually produced. The failures guided the fixes.
- Editing. In Reelkit, a 25-task benchmark grades each edit by inspecting the output frames.
Each of these tests grades the artefact the model produced. A model that says it fixed the table is not evidence that the table is fixed.