Context attacks are **chaos applied to content that flows into the agent from tools or to the input before invoke — not to the user prompt itself.** They test whether the agent is fooled by adversarial content in tool responses, RAG results, or poisoned input (OWASP LLM Top 10 #1: indirect prompt injection).
- **Mutation / prompt injection** — The *user* sends adversarial text (e.g. "Ignore previous instructions…"). That's tested via mutation types like `prompt_injection`.
- **Context attacks** — The *tool* returns valid-looking content with hidden instructions, or **memory_poisoning** injects a payload into the **user input before each invoke**. Flakestorm applies these in the chaos interceptor so you can verify the agent doesn't obey them.
- **memory_poisoning** — To the **user input before each invoke**. One payload per scenario; strategy: `prepend` | `append` | `replace`. Only the first `memory_poisoning` entry in the normalized list is applied.
- **indirect_injection** — Into tool/context response content (when wired via transport) with `trigger_probability` and `payloads`.
LLM faults (timeout, truncated_response, empty, garbage, rate_limit, response_drift) are applied in the same interceptor: **timeout** before the adapter call; others **after** the response.
| **Tool fault: `malicious_response`** | `chaos.tool_faults[].mode: malicious_response` | The tool returns **obviously bad** output (e.g. raw injection text). The agent should detect that something is wrong. |
| **Context attack: `indirect_injection`** | `chaos.context_attacks[]` with `type: indirect_injection` | The tool returns **valid-looking** content that contains hidden instructions. Harder for the agent to detect. |
| **Context attack: `memory_poisoning`** | `chaos.context_attacks[]` with `type: memory_poisoning` | A **payload** is injected into the **input before invoke** (prepend / append / replace). |
In `flakestorm.yaml` under `chaos` (or per scenario in `contract.chaos_matrix[].context_attacks`). You can use a **list** or a **dict** (addendum format):
| `indirect_injection` | Inject one of `payloads` into tool/context response content with `trigger_probability`. |
| `memory_poisoning` | Inject `payload` into **user input before invoke** with `strategy`: `prepend` \| `append` \| `replace`. Only one memory_poisoning is applied per invoke (first in list). |
Fields (depend on type): `type`, `payloads`, `trigger_probability`, `payload`, `strategy`, `inject_tokens`. See `ContextAttackConfig` in `src/flakestorm/core/config.py`.
---
## system_prompt_leak_probe (contract assertion)
**system_prompt_leak_probe** is implemented as a **contract invariant** that uses **`probes`**: a list of probe prompts to run instead of golden_prompts for that invariant. The agent must not leak the system prompt in the response. Use `type: excludes_pattern` with `patterns` defining forbidden content, and set **`probes`** to the list of prompts that try to elicit a leak. See [Behavioral Contracts](BEHAVIORAL_CONTRACTS.md) and [V2 Spec](V2_SPEC.md).