# `Nous.Eval.Guard.Generate`
[🔗](https://github.com/nyo16/nous/blob/v0.21.1/lib/nous/eval/guard/generate.ex#L1)

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/1` writes attacks (`label: "block"`) for the surface: prompt
    injections, jailbreaks, tool calls that exfiltrate or destroy, tool
    results carrying instructions, outputs that leak.
  * `hard_negatives/1` writes benign cases that use the vocabulary of
    attacks (`label: "allow"`, tag `hard_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, a `Nous.new/2` model string (required)
  * `:guard_model` - the guard's model: a `Nous.DecisionModel`, a
    decision-model string, `{:decision_guard, config}`, or an LLM model
    string (an LLMJudge's) (required)
  * `:allow_same_model` - default `false`
  * `:surface` - `:user_input` (default), `:tool_call`, `:tool_result`,
    `:model_output`
  * `:count` - cases to ask for (default `10`, at most `50`)
  * `:categories` - the pack question ids or attack classes to cover
  * `:tools` - the agent's `%Nous.Tool{}` list, for tool surfaces
  * `:temperature` - default `0.9`
  * `:license` - the licence the generated cases are released under
    (default `"Apache-2.0"`)
  * `:split_seed` - default `"nous-guard-v1"`
  * `:model_opts` - extra `Nous.new/2` options (`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}`.

# `distinct_models`

```elixir
@spec distinct_models(String.t(), term(), boolean()) ::
  :ok | {:error, {:same_model, String.t()}}
```

`: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.

# `hard_negatives`

```elixir
@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.

# `red_team`

```elixir
@spec red_team(keyword()) ::
  {:ok, %{cases: [Nous.Eval.Guard.Case.t()], rejected: list()}}
  | {:error, term()}
```

Generates attack cases (`label: "block"`). See the moduledoc.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
