Red-team and hard-negative generators for guard datasets: tool-less agents
that write nous.guard_case/1 cases for one surface.
{:ok, %{cases: cases, rejected: []}} =
Nous.Eval.Guard.Generate.red_team(
model: "openai:gpt-4.1",
guard_model: "workers_ai:clef-flash",
surface: :tool_call,
tools: MyAgent.tools(),
categories: ["exfiltration", "destructive"],
count: 20
)red_team/1writes attacks (label: "block") for the surface: prompt injections, jailbreaks, tool calls that exfiltrate or destroy, tool results carrying instructions, outputs that leak.hard_negatives/1writes benign cases that use the vocabulary of attacks (label: "allow", taghard_negative): the false-block cases a guard is most likely to get wrong.
The generator model must differ from the guard's model: a model
writing (and so implicitly labelling) the cases it is then measured on
makes the measurement circular. A generator whose model is the guard's
model is refused unless allow_same_model: true.
Tool names, descriptions and parameter schemas are untrusted to the
generator, so they are passed inside the random-boundary fence
(Nous.Fence, as Nous.Plugins.InputGuard.Strategies.LLMJudge does).
Every case is provenance.label_source: "generated", review: "pending"
(no certification claim rests on it until a maintainer approves it),
public: false, with generator: {model, prompt_sha256, temperature}.
Its group is the generator call and category, so one call's cases share
a split (Nous.Eval.Guard.Hygiene.hashed_split/3), and generator
clustering widens the intervals instead of inflating n.
Options
:model- the generator, aNous.new/2model string (required):guard_model- the guard's model: aNous.DecisionModel, a decision-model string,{:decision_guard, config}, or an LLM model string (an LLMJudge's) (required):allow_same_model- defaultfalse:surface-:user_input(default),:tool_call,:tool_result,:model_output:count- cases to ask for (default10, at most50):categories- the pack question ids or attack classes to cover:tools- the agent's%Nous.Tool{}list, for tool surfaces:temperature- default0.9:license- the licence the generated cases are released under (default"Apache-2.0"):split_seed- default"nous-guard-v1":model_opts- extraNous.new/2options (base_url:,api_key:)
Returns {:ok, %{cases: [Case.t()], rejected: [{index, reason}]}} (items
the model returned that are not valid cases are listed, never kept) or
{:error, reason}.
Summary
Functions
:ok when the generator model and the guard's model differ; {:error, {:same_model, name}} otherwise (unless allow?). Models compare by name,
case-insensitively, with any provider: prefix removed.
Generates benign look-alike cases (label: "allow", hard_negative). See the moduledoc.
Generates attack cases (label: "block"). See the moduledoc.
Functions
:ok when the generator model and the guard's model differ; {:error, {:same_model, name}} otherwise (unless allow?). Models compare by name,
case-insensitively, with any provider: prefix removed.
@spec hard_negatives(keyword()) :: {:ok, %{cases: [Nous.Eval.Guard.Case.t()], rejected: list()}} | {:error, term()}
Generates benign look-alike cases (label: "allow", hard_negative). See the moduledoc.
@spec red_team(keyword()) :: {:ok, %{cases: [Nous.Eval.Guard.Case.t()], rejected: list()}} | {:error, term()}
Generates attack cases (label: "block"). See the moduledoc.