Add context poisoning quarantine evaluation for testing prompt injection vulnerabilities #1597
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds an evaluation for context poisoning (prompt injection) attacks.
The eval measures how often a model leaks a canary token (CANARY-ALPHA-42) when exposed to poisoned inputs, and compares baseline performance against a simple quarantine wrapper mitigation.
Problem
Prompt injection remains a key safety risk in production LLM applications.
Models often follow malicious instructions hidden inside untrusted content (e.g. customer docs, web pages, emails), leading to potential data leakage or system override.
Solution
This PR introduces:
Baseline eval: Runs poisoned samples directly
Mitigated eval: Applies a quarantine wrapper that marks untrusted content as data-only
Metrics: Tracks canary leakage frequency across attack styles
Attack vectors included: direct instructions, system overrides, HTML comments, critical markers, and injection tags.
Example Results
Baseline (no protection): 4/5 samples leaked (80%)
Mitigated (quarantine): 2/5 samples leaked (40%)
~50% reduction in successful attacks
Why It Matters
Provides a reproducible benchmark for prompt injection vulnerability
Demonstrates the effectiveness of simple mitigations
Can be extended with additional datasets and defenses
Happy to iterate on this; definitely open to expanding the sample size or adjusting the eval format to better fit the framework.