# `Nous.Plugins.DecisionGuard.Pack`
[🔗](https://github.com/nyo16/nous/blob/v0.21.1/lib/nous/plugins/decision_guard/pack.ex#L1)

Behaviour for a `Nous.Plugins.DecisionGuard` question pack: the questions a
decision model answers about one surface, the probability bands that turn
the answers into a verdict, and the state the model sees.

Built-in packs:

| Pack | Surface | Event |
|---|---|---|
| `Nous.Plugins.DecisionGuard.Packs.UserInput` | `:user_input` | plugin `before_request/3` |
| `Nous.Plugins.DecisionGuard.Packs.ToolCall` | `:tool_call` | `:pre_tool_use` |
| `Nous.Plugins.DecisionGuard.Packs.ToolResult` | `:tool_result` | `:post_tool_use` |
| `Nous.Plugins.DecisionGuard.Packs.ModelOutput` | `:model_output` | `:post_response` |

## Model families

Prompts and thresholds do not transfer between decision-model families
(Red Hat measured a policy tuned for one family costing another several
points). Every pack declares the family it was tuned on (`model_family/0`,
`"clef"` for the built-ins, covering Clef and Clef-Flash), and `bands/1`
**refuses** to hand out default bands for any other family: pass `:bands`
for every question instead.

## Questions and bands

Questions are an ordered keyword list (Clef decides them jointly, in
order). Every risk question is phrased so that the risky answer reads high
(`"true"` for a `:noul`). Bands are `Nous.Hook.Decision` bands:
`{allow_below, deny_at}`.

# `surface`

```elixir
@type surface() :: :user_input | :tool_call | :tool_result | :model_output
```

# `verdict`

```elixir
@type verdict() :: Nous.Hook.Decision.verdict()
```

# `bands`

```elixir
@callback bands(opts :: keyword()) :: %{required(atom()) =&gt; term()}
```

Default bands for `questions(opts)`, keyed by question id. `opts[:preset]`
selects a preset; `opts[:model_family]` must equal `model_family/0` (see
`ensure_family!/2`), or this raises `ArgumentError`.

# `combine`
*optional* 

```elixir
@callback combine(
  answers :: %{required(atom()) =&gt; Nous.DecisionModel.Answer.t()},
  verdict()
) :: verdict()
```

Optional cross-question rule, run per chunk after the bands. It can only
raise the verdict. See `Nous.Hook.Decision` (`:combine`).

# `model_family`

```elixir
@callback model_family() :: String.t()
```

The decision-model family the questions and bands were tuned on.

# `questions`

```elixir
@callback questions(opts :: keyword()) :: [{atom(), keyword()}]
```

The questions, in order. `opts[:include]` switches on opt-in groups (see
each pack).

# `state`

```elixir
@callback state(payload :: map(), env :: map()) :: term()
```

The state the decision model sees: a JSON-framed map whose keys sort with
`"untrusted_content"` last. `payload` is the hook payload (`%{content: text}`
on the user-input surface); `env` is `t:Nous.Hook.Decision.env/0`.

# `surface`

```elixir
@callback surface() :: surface()
```

The surface this pack guards.

# `build`

```elixir
@spec build(module(), keyword()) :: keyword()
```

Resolves `pack`'s questions, bands and combine rule against user overrides,
as `Nous.Hook.Decision.new/1` options (`:questions`, `:bands`, `:combine`).

`opts`:

  * `:questions` - `nil` (the pack's), `{:replace, questions}` or
    `{:extend, questions}` (appended after the pack's).
  * `:bands` - `%{id => band}`; wins over the pack's. When every question
    has one, the pack's defaults are not consulted (so another family
    works); otherwise they are, and `bands/1` refuses a foreign family.
  * `:preset`, `:include`, `:model_family` - passed to the pack.

The pack's `combine/2` applies only to its own (not replaced) questions on
its own family.

# `ensure_family!`

```elixir
@spec ensure_family!(module(), keyword()) :: :ok
```

Raises `ArgumentError` unless `opts[:model_family]` is `pack`'s family.
Packs call it from `bands/1`.

# `model_family`

```elixir
@spec model_family(Nous.DecisionModel.t(), keyword()) :: String.t() | nil
```

The decision model's family: `opts[:model_family]` when given, else
`"clef"` when the model name contains "clef", else `nil`.

# `resolve_model!`

```elixir
@spec resolve_model!(Nous.DecisionModel.t() | String.t()) :: Nous.DecisionModel.t()
```

A `%Nous.DecisionModel{}` from a struct or a `Nous.DecisionModel.parse/2`
string.

---

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