Generative AI security is the work of keeping a language model from being talked into leaking data or taking actions nobody approved. The hard part is that the model reads instructions and data through the same channel. Any text it sees can try to steer it, so the defences that matter sit around the model, in permissions and checks you control.
This guide walks through the risks that show up in real deployments and the controls worth building first, using the main security frameworks as the map.
What generative AI security actually covers
Classic application security assumes code does what it says. A generative model breaks that assumption, because its behaviour depends on whatever text lands in its context window, meaning the block of text the model reads before it answers. Change the text and you change the behaviour.
The most useful map of the territory is the OWASP Top 10 for LLM Applications, updated for 2025. It lists the risks that come up again and again in model-backed products:
- LLM01 Prompt Injection
- LLM02 Sensitive Information Disclosure
- LLM03 Supply Chain
- LLM04 Data and Model Poisoning
- LLM05 Improper Output Handling
- LLM06 Excessive Agency
- LLM07 System Prompt Leakage
- LLM08 Vector and Embedding Weaknesses
- LLM09 Misinformation
- LLM10 Unbounded Consumption
Most of the list traces back to two facts. The model cannot reliably tell your instructions from someone else's, and the model's output often flows straight into a browser or a shell. Everything else is detail. Important detail, the kind that ends up in an incident report, but detail.
Some exposure is a choice about where you use the model at all. Before you secure a workflow, check that it belongs on a model in the first place; our guide to appropriate tasks for generative AI covers which jobs to keep off it entirely.
Prompt injection, the risk with no clean fix
Prompt injection happens when text the model reads changes what it does. OWASP splits it in two. Direct injection comes from the user typing into the chat. Indirect injection hides in content the model pulls in on its own, such as a web page or an uploaded file.
Indirect injection is the dangerous one, because the attacker never touches your app. They plant a sentence in a document and wait for your assistant to summarise it. If that assistant can send email, the planted sentence can ask it to forward the inbox somewhere.
The UK's National Cyber Security Centre made the point bluntly in a December 2025 post, Prompt injection is not SQL injection (it may be worse). SQL injection was fixed at the root with parameterised queries, which stop a database from ever treating input as a command. A language model has no equivalent separation. The NCSC describes the model as "inherently confusable" and says the risk may never be fully mitigated. OWASP lands in the same place, calling it unclear whether fool-proof prevention exists.
That changes the goal. The job becomes limiting what a successful injection can reach. The NCSC endorses a rule from researcher Simon Willison: when a model processes content from some party, its privileges drop to that party's level. An assistant reading external email should hold no privileged tools while it does so.
Blocklists of phrases like "ignore previous instructions" fail for a simple reason. Attackers can rephrase forever, and a keyword filter is a game of whack-a-mole where the moles have a thesaurus.
Sensitive data leakage and system prompt leaks
Models leak in two directions. They reveal data they were given, and they reveal the instructions they were built with.
Sensitive information disclosure covers the first. Anything placed in the context window can come back out in an answer, including customer records pulled in by retrieval and API keys someone pasted into a prompt during testing. Retrieval, meaning the step that fetches documents to ground an answer, makes this worse when it ignores the asking user's permissions. If the search index holds the board minutes, a junior employee's question can surface them.
System prompt leakage is the second. Treat your system prompt as public. Users will extract it, and some of them will post it online within a week of launch. The real failure is putting secrets there, such as credentials or business rules that only work while nobody knows them. Keep authorisation in code, where the model cannot be argued out of it.
Vibe coding security: generated code ships with old bugs
Vibe coding means describing what you want and accepting the code a model writes, often without reading it closely. It is fast. It also imports a familiar class of bugs at speed.
Veracode's 2025 GenAI Code Security Report tested more than 100 models on coding tasks. In 45% of samples, the generated code introduced an OWASP Top 10 vulnerability. Java was the worst language at 72%. Models failed to defend against cross-site scripting in 86% of relevant samples.
The finding that should change your process: newer and larger models wrote more working code without writing more secure code. Security performance stayed flat across model sizes. Waiting for the next release will not fix this one, however confidently the launch keynote says otherwise.
The practical response is boring and effective. Run the same static analysis and dependency checks on generated code that you run on human code, and review anything touching authentication or user input by hand. OWASP calls the related failure improper output handling: treating model output as trusted. Handle it like input from a stranger.
Generative AI security controls that hold up
The controls that work share one trait. They are deterministic code wrapped around the model, so they behave the same way whatever the prompt says. OWASP's prompt injection guidance and the NCSC post agree on the core set:
- Least privilege for tools. Give the model the narrowest tools and API scopes the task needs, using the application's own tokens.
- Privilege drop on untrusted content. When the model reads outside content, remove access to tools that could cause harm.
- Human approval for high-risk actions. Payments and deletions wait for a person.
- Mark external content. Wrap retrieved text in clear delimiters so the model gives it less weight. This lowers success rates without stopping attacks.
- Validate output in code. Check formats with a parser and encode anything bound for a browser or shell.
- Log everything. Keep the full input and output of every call, tool calls included. A burst of failed tool calls is often the first sign of an attack in progress.
- Test adversarially. Run injection attempts against your own system on a schedule, treating the model as an untrusted user.
Agents raise the stakes, since an agent that can act turns a bad answer into a bad action. The same principle applies to agents that drive a desktop, covered in our piece on AI agents that control mouse and keyboard input. For designing tool permissions into an agent from the first line, Agentic AI Engineering covers system prompts and tool design for production agents.
Regulated teams will also need evidence that these controls exist. Our guide to choosing an AI compliance solution covers where software helps with that record-keeping and where it stops.
What an AI security engineer does differently
An AI security engineer secures systems built on models. The job borrows from application security and adds threat modelling for text, meaning the habit of asking what happens when every document the model reads was written by an attacker.
Day to day, that looks like reviewing which tools each agent holds and red-teaming prompts before launch. Model logs go into the monitoring the security team already watches. The skill set is less exotic than the title suggests. Most of the work is permissions and review, applied to a component that occasionally takes instructions from a PDF.
For managers deciding how much of this to build in-house, AI Systems in Business covers securing and scaling AI systems from the business side.
If you do one thing this week, list every tool your models can call and ask what the worst injected instruction could do with each. Remove the tools where the answer frightens you, and put a human approval in front of the rest.