Implementation:Promptfoo Promptfoo doGenerateRedteam
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, Reporting |
| Last Updated | 2026-02-14 08:00 GMT |
Overview
Concrete tool for generating adversarial test cases and outputting them as reusable YAML evaluation configurations, provided by the Promptfoo framework.
Description
The doGenerateRedteam function orchestrates the full generation pipeline: parsing red team config, calling synthesize for test generation, calculating test counts, and serializing results as YAML. It handles both file output and programmatic return.
Usage
Import this function for programmatic red team test generation with file output. It is the handler for the `promptfoo redteam generate` CLI command.
Code Reference
Source Location
- Repository: promptfoo
- File: src/redteam/commands/generate.ts
- Lines: L153-823
Signature
export async function doGenerateRedteam(
options: Partial<RedteamCliGenerateOptions>,
): Promise<Partial<UnifiedConfig> | null>
Import
import { doGenerateRedteam } from './redteam/commands/generate';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| options.plugins | RedteamPluginObject[] | No | Plugin configurations |
| options.strategies | RedteamStrategyObject[] | No | Strategy configurations |
| options.purpose | string | No | Purpose override (skips extraction) |
| options.numTests | number | No | Tests per plugin (default: 5) |
| options.output | string | No | Output YAML file path |
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | Partial<UnifiedConfig> or null | Generated config with test cases, or null on error |
Usage Examples
Generate Red Team Config
import { doGenerateRedteam } from './redteam/commands/generate';
const config = await doGenerateRedteam({
config: './redteamconfig.yaml',
output: './generated-tests.yaml',
numTests: 10,
});
if (config) {
console.log(`Generated ${config.tests?.length} test cases`);
}