Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Promptfoo Promptfoo applyStrategies

From Leeroopedia
Revision as of 13:43, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Promptfoo_Promptfoo_applyStrategies.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment