Security for AI: How to Protect Models and Data
Security for AI protects the data, model, prompts and outputs of an AI system. Learn the threats, the controls for each, and a five-step start.
On this page
Short answer
Security for AI means protecting the data, model, prompts and outputs of an AI system from misuse, theft and manipulation. The core controls are permission-filtered retrieval, input and output checks, scoped agent tools with approval gates, and regular re-testing after every change.
What is security for AI?
Security for AI is the practice of protecting an AI system - its data, its model, its prompts and its outputs - from misuse, theft and manipulation. It covers everything an attacker can reach: the training data, the retrieval documents, the model weights, the prompts users send, and the tools the system can call.
It differs from traditional application security because the model itself is a new attack surface. A prompt is code the user writes, an output can leak data the user should not see, and a model can be tricked into actions its builders never intended. The same controls you use for a web app still apply, but they are not enough on their own.
Security for AI is not a single product. It is a set of habits: limit what the model can see and do, check what goes in and what comes out, log every action, and assume that someone will try to break each of those controls. If you want the vendor view, AI security companies for startups lists tools built for this job.
What can go wrong with an AI system?
Most AI security failures fall into a small set of patterns. Learn the patterns first, because each one points to a different control.
| Threat | What happens | Where it bites |
|---|---|---|
| Prompt injection | Hidden instructions in content steer the model | Chat, agents, summarised pages |
| Data poisoning | Bad data in training or retrieval skews answers | Training sets, knowledge bases |
| Output leaks | Answers reveal data the user should not see | Support, search, copilots |
| Model theft | Queries copy the model or its behaviour | Public APIs, fine-tuned models |
| Tool abuse | An agent uses its tools to act wrongly | Agents with write access |
| Supply-chain attacks | A tainted library or model reaches production | Dependencies, hosted models |
Prompt injection is the most common in practice, because any text the model reads - a web page, a document, a ticket - can carry instructions. Treat all model input as untrusted, even when it comes from your own documents. For the injection case specifically, how to prevent prompt injection covers the defences in depth.
How do you protect training and retrieval data?
Protecting data starts with knowing what the model can reach. List every source: training files, retrieval documents, databases the agent can query, and files users upload. If a source holds personal or confidential data, the model needs the same access rules as a person reading it.
Three controls do most of the work. First, filter retrieval by the user's permissions, so a search never returns a document the user cannot open. Second, remove or mask personal data before it enters a training set or an index, and keep a record of what was removed. Third, separate data by sensitivity, so a support bot cannot reach finance files even if a prompt asks it to.
Review the sources on a schedule. Documents change, permissions drift, and a folder that was safe six months ago may hold a contract today. A quarterly review of what the model can reach catches that drift before a leak does.
How do you secure prompts and model outputs?
Prompts and outputs need checks on both sides. On the way in, filter for known attack patterns - instructions hidden in pasted content, requests to ignore system rules, and attempts to extract the system prompt. On the way out, check the answer before it reaches the user.
Output checks should look for three things: personal data that should not be shown, instructions or code the user did not ask for, and claims that cite a source the user cannot access. Any of the three should block the answer or send it to a human, not reach the user unreviewed.
Keep the system prompt out of the conversation. A model that repeats its instructions on request hands an attacker the rules of the system, so test that refusal yourself before launch and re-test it after every prompt change.
Log prompts and outputs for a sample of traffic, not everything. Full logging of personal conversations creates its own privacy problem, so sample, redact and set a retention limit.
How do you control what agents can do?
An agent is only as safe as the tools it can call. Give each agent its own credentials, scoped to the smallest set of actions its job needs, and never share one service account across agents.
Put approval gates in front of irreversible actions: sending money, deleting records, changing permissions, or contacting a customer. The agent can prepare the action, but a human or a rule must approve it. Read-only work - searching, drafting, summarising - can run without a gate.
Add a kill switch that stops an agent in seconds: revoke its credentials, pause its queue and freeze its tools. Test the switch before launch, because a switch you have never used will not work when you need it. Keep an audit log of every tool call, so a bad action can be traced to the prompt and the data that caused it.
Review permissions when the agent's job changes. An agent that gains a new tool gains a new attack surface, and the review should happen before the tool goes live, not after an incident.
How do you start securing an AI system in 5 steps?
Start with the highest-risk paths, not with a full programme. A small team can close the worst gaps in weeks.
- List what the model can reach. Data sources, tools, APIs and the people who can use it.
- Filter retrieval by user permission, so no answer can leak a document the user cannot open.
- Add input and output checks, starting with prompt injection and personal data in answers.
- Scope agent tools and add approval gates for irreversible actions, plus a tested kill switch.
- Log, review and re-test. Sample traffic weekly, review failed checks, and re-run your attack tests after every change.
Governance sits above these steps: who owns the risk, what is allowed, and how incidents are handled. If that layer is missing, what AI governance is is the place to start.
Example (hypothetical): a support agent that almost leaked a contract
Example (hypothetical): a support team launches an AI agent that answers from a knowledge base of 8,000 articles. A customer asks about renewal terms, and the agent quotes a clause from a contract file that was indexed by mistake - a file only the legal team should see.
The team finds three gaps. First, the index had no permission filter, so any document could be retrieved for any user. Second, the contract folder was indexed with the help centre. Third, nobody had tested the agent with a question about another customer's terms.
The fix takes a week. The team removes the contract folder from the index, adds permission filtering to retrieval, and writes 20 test questions that try to reach restricted documents. Each test now runs before every deployment, and the permission review repeats every quarter. The agent still answers renewal questions, but only from public help articles.
What are the common mistakes?
The most common AI security mistakes are treating the model as trusted, giving agents broad access, and never testing the defences you built.
- Trusting model input, including text from your own documents and web pages.
- Indexing everything, so restricted files become retrievable by anyone.
- Agents with shared, broad credentials, so one bad prompt can act across systems.
- No output checks, so personal data or hidden instructions reach the user.
- Logging everything without redaction, which creates a second privacy problem.
- Testing security once at launch, then never again after prompts and tools change.
Security for AI is mostly discipline: narrow access, check inputs and outputs, and re-test after every change. The tools help, but the habits are what hold.
Key takeaways
- A prompt is untrusted input, even when it comes from your own documents
- Filter retrieval by user permission so no answer leaks a restricted file
- Check outputs for personal data, hidden instructions and inaccessible sources
- Give each agent scoped credentials and gate irreversible actions
- Re-test your defences after every prompt, tool or data change
Frequently asked questions
What is the biggest security risk in AI systems?
Prompt injection is the most common, because any text the model reads can carry hidden instructions. Data leaks from unfiltered retrieval are close behind. Both are fixed with controls, not with a better model.
How is security for AI different from normal app security?
The model adds new attack surfaces: prompts are user-written code, outputs can leak data, and agents can act through tools. Standard controls still apply, but you also need input and output checks, retrieval filtering and scoped agent permissions.
Do I need special tools to secure an AI system?
Not at first. Permission filtering, input and output checks, scoped credentials and logging cover most of the risk. Specialist tools help with detection and evaluation, and make sense once the basics are in place.
Can an AI model leak training data?
Yes, models can repeat text from training data, and retrieval systems can return restricted documents. Mask personal data before training or indexing, filter retrieval by permission, and test with questions aimed at restricted content.
What should an agent never be allowed to do alone?
Irreversible actions: sending money, deleting records, changing permissions or contacting customers. The agent can prepare these, but a human or a rule must approve them. Read-only work can run without a gate.
How often should AI security be tested?
Re-run your attack tests after every prompt, tool or data change, and review a sample of real traffic weekly. A defence tested once at launch will quietly stop working as the system changes.