Implementation:Promptfoo Promptfoo applyStrategies
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, Adversarial_ML |
| Last Updated | 2026-02-14 08:00 GMT |
Overview
Concrete tool for applying attack delivery strategies to transform base adversarial test cases, provided by the Promptfoo red team framework.
Description
The applyStrategies function iterates over configured strategies, loading each strategy module and applying its transformation to the base test cases. It tracks generation statistics per strategy and handles both built-in strategies (from the Strategies registry) and custom file-based strategies.
Usage
This function is called internally by synthesize after plugin-based test generation. It is not typically called directly.
Code Reference
Source Location
- Repository: promptfoo
- File: src/redteam/index.ts
- Lines: L350-567
Signature
async function applyStrategies(
testCases: TestCaseWithPlugin[],
strategies: RedteamStrategyObject[],
injectVar: string,
excludeTargetOutputFromAgenticAttackGeneration?: boolean,
): Promise<{
testCases: TestCaseWithPlugin[];
strategyResults: Record<string, { requested: number; generated: number }>;
}>
Import
// Internal function within src/redteam/index.ts
// Not exported directly; called by synthesize()
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| testCases | TestCaseWithPlugin[] | Yes | Base test cases from plugin generation |
| strategies | RedteamStrategyObject[] | Yes | Strategies to apply (e.g., base64, jailbreak, goat) |
| injectVar | string | Yes | The variable name where attacks are injected |
Outputs
| Name | Type | Description |
|---|---|---|
| testCases | TestCaseWithPlugin[] | Combined base + strategy-transformed test cases |
| strategyResults | Record<string, { requested, generated }> | Per-strategy generation statistics |
Usage Examples
Strategy Application Flow (Internal)
// Called within synthesize():
const { testCases: allTestCases, strategyResults } = await applyStrategies(
pluginTestCases,
[{ id: 'base64' }, { id: 'jailbreak' }, { id: 'goat' }],
'query',
);
// allTestCases now contains original + base64-encoded + jailbreak + GOAT variants