Documentation
¶
Overview ¶
Package redteam provides adversarial testing generators for AI safety evaluation. It generates attacks that attempt to bypass agent guardrails.
Index ¶
Constants ¶
const MaxPerType = 5
MaxPerType is how many cases a generator can produce: each has five fixed templates.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttackType ¶
type AttackType string
AttackType categorises adversarial attacks.
const ( AttackInjection AttackType = "injection" AttackJailbreak AttackType = "jailbreak" AttackLeakage AttackType = "leakage" AttackHallucination AttackType = "hallucination" AttackOfftopic AttackType = "offtopic" )
type Config ¶
type Config struct {
Generators []Generator
Config *GenerateConfig
}
Config configures a red team evaluation.
type GenerateConfig ¶
type GenerateConfig struct {
SuiteID string
Count int
SystemPrompt string
Difficulty string
Extra map[string]any
}
GenerateConfig provides context for attack generation.
type Generator ¶
type Generator interface {
Name() string
Type() AttackType
Generate(ctx context.Context, cfg *GenerateConfig) ([]*testcase.Case, error)
}
Generator creates adversarial test cases.
func GeneratorFor ¶
func GeneratorFor(t AttackType) (Generator, bool)
GeneratorFor returns the built-in generator for an attack type.
type HallucinationGenerator ¶
type HallucinationGenerator struct{}
HallucinationGenerator creates test cases that probe for hallucination.
func NewHallucinationGenerator ¶
func NewHallucinationGenerator() *HallucinationGenerator
NewHallucinationGenerator creates a hallucination probe generator.
func (*HallucinationGenerator) Generate ¶
func (g *HallucinationGenerator) Generate(_ context.Context, cfg *GenerateConfig) ([]*testcase.Case, error)
func (*HallucinationGenerator) Name ¶
func (g *HallucinationGenerator) Name() string
func (*HallucinationGenerator) Type ¶
func (g *HallucinationGenerator) Type() AttackType
type InjectionGenerator ¶
type InjectionGenerator struct{}
InjectionGenerator creates prompt injection attack test cases.
func NewInjectionGenerator ¶
func NewInjectionGenerator() *InjectionGenerator
NewInjectionGenerator creates a prompt injection generator.
func (*InjectionGenerator) Generate ¶
func (g *InjectionGenerator) Generate(_ context.Context, cfg *GenerateConfig) ([]*testcase.Case, error)
func (*InjectionGenerator) Name ¶
func (g *InjectionGenerator) Name() string
func (*InjectionGenerator) Type ¶
func (g *InjectionGenerator) Type() AttackType
type JailbreakGenerator ¶
type JailbreakGenerator struct{}
JailbreakGenerator creates jailbreak attempt test cases.
func NewJailbreakGenerator ¶
func NewJailbreakGenerator() *JailbreakGenerator
NewJailbreakGenerator creates a jailbreak generator.
func (*JailbreakGenerator) Generate ¶
func (g *JailbreakGenerator) Generate(_ context.Context, cfg *GenerateConfig) ([]*testcase.Case, error)
func (*JailbreakGenerator) Name ¶
func (g *JailbreakGenerator) Name() string
func (*JailbreakGenerator) Type ¶
func (g *JailbreakGenerator) Type() AttackType
type LeakageGenerator ¶
type LeakageGenerator struct{}
LeakageGenerator creates system prompt extraction test cases.
func NewLeakageGenerator ¶
func NewLeakageGenerator() *LeakageGenerator
NewLeakageGenerator creates a leakage generator.
func (*LeakageGenerator) Generate ¶
func (g *LeakageGenerator) Generate(_ context.Context, cfg *GenerateConfig) ([]*testcase.Case, error)
func (*LeakageGenerator) Name ¶
func (g *LeakageGenerator) Name() string
func (*LeakageGenerator) Type ¶
func (g *LeakageGenerator) Type() AttackType
type OfftopicGenerator ¶
type OfftopicGenerator struct{}
OfftopicGenerator creates test cases that attempt to derail the agent from its intended domain.
func NewOfftopicGenerator ¶
func NewOfftopicGenerator() *OfftopicGenerator
NewOfftopicGenerator creates an off-topic manipulation generator.
func (*OfftopicGenerator) Generate ¶
func (g *OfftopicGenerator) Generate(_ context.Context, cfg *GenerateConfig) ([]*testcase.Case, error)
func (*OfftopicGenerator) Name ¶
func (g *OfftopicGenerator) Name() string
func (*OfftopicGenerator) Type ¶
func (g *OfftopicGenerator) Type() AttackType
type Report ¶
type Report struct {
TotalAttacks int `json:"total_attacks"`
Bypasses int `json:"bypasses"`
BypassRate float64 `json:"bypass_rate"`
ByType map[AttackType]TypeResult `json:"by_type"`
}
Report holds the results of a red team evaluation.
type TypeResult ¶
type TypeResult struct {
Total int `json:"total"`
Bypasses int `json:"bypasses"`
Rate float64 `json:"rate"`
}
TypeResult summarises results for a specific attack type.