# Data Poisoning

> The Data Poisoning is an attack where manipulated data is added to a training or retrieval dataset to change model behavior.

## What is data poisoning in AI?

The attack where an attacker injects crafted examples into training data or into documents used for RAG. The model then produces wrong answers or behaves maliciously on specific triggers.

- Topic: Security & Ethics
- Type: cyberattack

## Example

Wrong:

```js
for (const url of submittedUrls) {
  await index.add(await fetchText(url));
}
```

Right:

```js
for (const url of submittedUrls) {
  if (!TRUSTED_HOSTS.has(new URL(url).hostname)) continue;
  const text = await fetchText(url);
  await index.add(text, { source: url, addedAt: Date.now() });
}
```

Indexing only trusted sources and recording where each document came from makes poisoned content harder to add and easier to remove.

## Key points

- Documents added to a RAG index come from trusted sources and record where they came from.
- User-submitted content is reviewed or filtered before it enters training or retrieval data.

## Interview questions

### Can data poisoning affect a RAG system?

Yes. If attackers can add documents to the index, they can make the model return false answers or hidden instructions when those documents are retrieved.

### What is the difference between data poisoning and prompt injection?

Data poisoning changes the data a model learns from or retrieves. Prompt injection gives the model instructions at runtime.

### How do I detect poisoned data?

Track the source of every document, review user-submitted content, and run evals that check for unexpected answers on trigger phrases.

## Related cards

- [RAG](https://wonderium.dev/ai/rag.md)
- [Indirect Prompt Injection](https://wonderium.dev/ai/indirect-prompt-injection.md)
- [Dataset](https://wonderium.dev/ai/dataset.md)
- [Training](https://wonderium.dev/ai/training.md)
- [Vector Database](https://wonderium.dev/ai/vector-database.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/data-poisoning
- Last updated: 2026-11-25
