Tribunal.RedTeam.Plugin.Base behaviour (Tribunal v1.4.0)

Copy Markdown View Source

Shared implementation for the built-in LLM-driven red-team plugins.

use Tribunal.RedTeam.Plugin.Base injects id/0, severity/0, and a full generate/1 pipeline: required-option validation, the plugin and attacker telemetry spans, the attacker call, attack extraction, and per-case emission. The using module supplies only the parts that differ between plugins:

  • meta_prompt/1 — build the attacker meta-prompt from the call opts (:purpose, :count, and any plugin-specific keys like :policy).
  • expected/1 — build the expected clause carried into each generated case (the assertion the judge runs against the target's response).
  • goal_description/0 — the schema description for each attack's goal.

Options

  • :id — required. The plugin id atom.
  • :severity — required. :low, :medium, or :high.
  • :required — required option keys, validated before generation. Defaults to [:purpose].
  • :default_count — attacks per call when :count is absent. Defaults to 5.

Example

defmodule MyApp.RedTeam.Plugins.Custom do
  use Tribunal.RedTeam.Plugin.Base, id: :custom, severity: :medium

  @impl true
  def meta_prompt(opts), do: "Attack #{opts[:purpose]} ..."

  @impl true
  def expected(opts), do: %{custom: %{purpose: opts[:purpose]}}

  @impl true
  def goal_description, do: "One sentence on what the attack elicits."
end

Summary

Types

opts()

@type opts() :: keyword()

Callbacks

expected(opts)

@callback expected(opts()) :: map()

goal_description()

@callback goal_description() :: String.t()

meta_prompt(opts)

@callback meta_prompt(opts()) :: String.t()