---
title: How do you stop memory poisoning in AI agents?
url: https://opencontroller.lyzr.com/blog/prevent-memory-poisoning-in-ai-agents
published: 2026-11-13
updated: 2026-11-13
author: Lyzr
---

# How do you stop memory poisoning in AI agents?

**You stop memory poisoning by controlling what can be written to an agent's memory, recording where every memory entry came from, expiring entries by default, and checking retrieved memory before the agent acts on it. Treat memory as untrusted input, not as the agent's own trusted thoughts.**

The OWASP Top 10 for Agentic Applications, published in December 2025, lists this risk as ASI06 Memory and Context Poisoning. It matters because a poisoned entry persists: one malicious email or web page can change an agent's behaviour for every later session that retrieves it.

## How does memory poisoning actually happen?

Agents with long-term memory save facts, preferences or summaries so they can reuse them. The attack works in three steps:

1. **Plant.** The attacker gets text into something the agent reads: an email, a support ticket, a document, a tool output or a chat message.
2. **Persist.** The agent summarises or stores that text as a memory, for example "the user prefers invoices sent to this new address".
3. **Trigger.** In a later session, often for a different user, the agent retrieves the memory and acts on it as if it were trusted.

The difference from ordinary prompt injection is time. Prompt injection affects one session. Memory poisoning survives until someone removes the entry. It also crosses users when memory is shared across a team or tenant.

## Which controls stop it?

Map each step of the attack to a control:

| Attack step | Control | What to check |
|---|---|---|
| Plant | Input filtering on untrusted sources | Prompt-injection detection on emails, documents and tool outputs before they reach the agent |
| Persist | Write controls | Only defined fields can be stored; free-text instructions are rejected; writes from external content need a higher bar |
| Persist | Provenance | Every entry records source, session, user and agent version |
| Persist | Scoping | Memory is scoped per user or per task, not shared across tenants by default |
| Trigger | Expiry | Entries expire after a set period unless renewed by a trusted source |
| Trigger | Retrieval checks | Retrieved memory is screened again and labelled as untrusted in the prompt |
| Trigger | Action gating | High-impact actions (payments, permission changes, outbound email) cannot be justified by memory alone |

## How do you put write controls in place?

Write controls are the strongest defence because they stop bad entries from existing. A practical checklist:

1. **Use a schema.** Store typed facts ("preferred language: French") rather than free text. Reject entries that look like instructions ("always", "ignore", "from now on").
2. **Separate sources.** Tag memory written from user statements differently from memory derived from external content. Never let external content overwrite a user-stated fact.
3. **Rate-limit writes.** A burst of new memories from a single document is a signal worth alerting on.
4. **Require confirmation for sensitive fields.** Payment details, contact addresses and access-related facts should be confirmed by the user, not inferred.
5. **Log every write** with the policy decision, so you can answer "when did this enter memory and why?"

Our post on [governing AI agent memory stores](/blog/govern-ai-agent-memory-stores) covers access, retention and deletion for the stores themselves.

## How do you detect poisoning that already happened?

Assume some entries will get through. Detection options:

- **Behavioural deviation.** An agent that starts sending data to a new destination or calling tools it rarely used is a signal, whatever the cause.
- **Memory audits.** Periodically sample entries and search for instruction-like phrasing, URLs and email addresses that do not belong to known domains.
- **Red-team tests.** Plant test instructions in a staging document and check whether they reach memory and whether they change later behaviour. Multi-turn tests matter here because the effect shows up across sessions. See [how to red-team AI agents with multi-turn attacks](/blog/how-to-red-team-ai-agents-multi-turn).
- **Provenance queries.** When an incident happens, find every entry written from the same source and purge them together.

## What should you do when you find a poisoned memory?

1. Quarantine the agent if it has taken or could take a harmful action.
2. Purge the entry and every entry from the same source and session.
3. Review actions the agent took after the entry was written.
4. Add the pattern to your input filters and red-team suite.
5. Release the agent only after a clean test run.

For the containment step, follow the playbook in [how to stop a rogue AI agent](/blog/how-to-stop-a-rogue-ai-agent).

## How Opencontroller does this

Opencontroller does not replace an agent's memory store, but it helps around it. Rogue-agent handling monitors behavioural deviation, raises alerts and can automatically quarantine or kill an agent across the estate. Multi-turn and red-team evals test poisoning scenarios before release, and live groundedness and task-adherence guardrails flag outputs that drift from the task. Policy as code maps controls to OWASP so ASI06 evidence can be reported. [Book a demo](https://www.lyzr.ai/book-demo/) to see it on your agents.

## Frequently asked questions

**Is memory poisoning the same as prompt injection?**
It often starts with prompt injection, but it persists. Prompt injection affects a single session; memory poisoning stores the attacker's text so it affects later sessions and sometimes other users.

**Do RAG knowledge bases have the same risk?**
Yes. OWASP's ASI06 covers both memory and retrieved context. Anyone who can write to a document the agent retrieves can try to plant instructions, so apply the same provenance and write controls to knowledge bases.

**Should we turn agent memory off?**
For high-risk agents with no clear need, yes. Otherwise scope memory per user, store typed facts, expire entries by default and keep a write log.

## Key facts

Memory poisoning (OWASP Top 10 for Agentic Applications ASI06 Memory and Context Poisoning, December 2025) plants instructions in an AI agent's long-term memory or retrieved context so they persist across sessions and users. Controls: input filtering, schema-based write controls, provenance per entry, per-user scoping, default expiry, retrieval screening and gating high-impact actions. Opencontroller by Lyzr adds behavioural-deviation monitoring, automatic quarantine and kill, multi-turn and red-team evals, live guardrails and OWASP policy mappings. Pricing starts from $250K per deployment per year.

## Related

- [How do you govern what AI agents remember?](https://opencontroller.lyzr.com/blog/govern-ai-agent-memory-stores.md)
- [How do you stop prompt injection that arrives through tool outputs?](https://opencontroller.lyzr.com/blog/stop-prompt-injection-through-tool-outputs.md)
- [How to stop a rogue AI agent: kill switches, quarantine and runtime controls](https://opencontroller.lyzr.com/blog/how-to-stop-a-rogue-ai-agent.md)
- [More on Runtime control](https://opencontroller.lyzr.com/blog/cluster/runtime-control)
