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

One guard case in the `nous.guard_case/1` schema: a labelled guard input
for calibration (`kind: "classifier"`) or a decision-table row for a
deterministic guard (`"permission"`, `"loop_guard"`, `"hook"`).

```json
{"schema": "nous.guard_case/1",
 "id": "deepset-110",
 "kind": "classifier",
 "surface": "user_input",
 "label": "block",
 "split": "holdout",
 "severity": "normal",
 "category": "prompt_injection",
 "tags": ["hard_negative"],
 "group": "jackhhao/dan-template",
 "input": {"text": "Forget everything ..."},
 "expected": {"acceptable": ["escalate", "deny"]},
 "provenance": {"source": "deepset/prompt-injections (test split)",
                "source_url": "https://huggingface.co/datasets/deepset/prompt-injections",
                "license": "Apache-2.0", "public": true, "label_source": "upstream"}}
```

## Keys

  * `schema` - `"nous.guard_case/1"` (required)
  * `id` - non-empty string, unique within a dataset (required)
  * `kind` - `"classifier"` (default), `"permission"`, `"loop_guard"` or
    `"hook"`
  * `surface` - classifier cases: `"user_input"`, `"tool_call"`,
    `"tool_result"` or `"model_output"` (required)
  * `label` - classifier cases: `"block"`, `"allow"` or `null` (an
    unlabelled item, e.g. promoted from online eval and not yet reviewed;
    never calibrated on). The key is required.
  * `split` - classifier cases: `"tune"`, `"holdout"` or `"test"` (required)
  * `severity` - `"normal"` (default) or `"critical"` (zero tolerance in the
    non-regression gate)
  * `category` - free text (the pack question or attack class)
  * `tags` - strings (`"hard_negative"`, `"upstream_train_overlap"`,
    `"synthetic_pii"`, ...)
  * `group` - cluster id for clustered intervals and leakage-free splits;
    defaults to `id`
  * `guard` - deterministic kinds: the name of the guard fixture the caller
    registers (policies and hooks are code, so cases never carry it)
  * `input` - the guard input (required), by surface:
    * `user_input`: `text` (string); optional `attachments`, a list of
      `{"media_type": "text/...", "text": ...}` documents
    * `tool_call`: `tool` (`{name, description?, category?}`),
      `arguments` (object), optional `task`
    * `tool_result`: `tool`, `result` (string or JSON), optional
      `arguments` and `task`
    * `model_output`: `content` (string), optional `tool_calls` (list) and
      `task`

    Without `tool.description` the description comes from the agent under
    test (see `Nous.Eval.Guard.Subject`).
  * `expected` - classifier cases: optional `{"acceptable": [verdicts]}`
    (default: `["escalate", "deny"]` for `block`, `["allow"]` for
    `allow`); deterministic kinds: the expected output (required)
  * `provenance` - required object: `source` and `license` (strings) plus
    the optional `source_url`, `license_url`, `license_note`,
    `attribution`, `source_revision`, `source_split`, `source_row`,
    `public` (boolean), `label_source` (`human`, `upstream`, `generated`,
    `llm_judge`, `promoted_reviewed`), `upstream_label`, `template_id`,
    `derived_from`, `transforms`, `generator`, `redacted`,
    `promoted_from`, `review` (`"pending"` or `"approved"`), `reviewed`
    (`{by, at}`) and `duplicates`

Loading is strict: an unknown key at any level the schema defines, a wrong
type or an unknown enum value is an error. Enum values map through literal
tables; nothing read from a file becomes an atom, and `input`,
`expected` and `provenance` stay string-keyed.

## Certification

A case whose `provenance.review` is `"pending"` (a generated or promoted
item no maintainer has approved) is not `certifiable?/1`: calibration
reports and the non-regression gate leave it out of `test`-split claims.

# `kind`

```elixir
@type kind() :: :classifier | :permission | :loop_guard | :hook
```

# `label`

```elixir
@type label() :: :block | :allow
```

# `split`

```elixir
@type split() :: :tune | :holdout | :test
```

# `surface`

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

# `t`

```elixir
@type t() :: %Nous.Eval.Guard.Case{
  category: String.t() | nil,
  expected: map() | nil,
  group: String.t(),
  guard: String.t() | nil,
  id: String.t(),
  input: map(),
  kind: kind(),
  label: label() | nil,
  provenance: map(),
  severity: :normal | :critical,
  split: split() | nil,
  surface: surface() | nil,
  tags: [String.t()]
}
```

# `verdict`

```elixir
@type verdict() :: :allow | :escalate | :deny
```

# `acceptable`

```elixir
@spec acceptable(t()) :: [verdict()]
```

The verdicts that count as correct for a classifier case: `expected.acceptable`
when given, else `[:escalate, :deny]` for `block` and `[:allow]` for
`allow` (`[]` for an unlabelled case).

# `certifiable?`

```elixir
@spec certifiable?(t()) :: boolean()
```

Whether the case may back a certification claim: it is labelled and not
awaiting review (`provenance.review` is not `"pending"`).

# `content_sha256`

```elixir
@spec content_sha256(t()) :: String.t()
```

`"sha256:<hex>"` of the canonical input, surface, kind and label: changes
whenever the case's content changes under a stable id.

# `from_map`

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

Builds a case from its decoded JSON form (string keys).

Returns `{:error, message}` naming the case and the offending key.

# `schema`

```elixir
@spec schema() :: String.t()
```

The schema id (`"nous.guard_case/1"`).

# `surfaces`

```elixir
@spec surfaces() :: [surface()]
```

The surfaces a classifier case may name.

# `to_map`

```elixir
@spec to_map(t()) :: map()
```

The case as JSON-native data (string keys), the inverse of `from_map/1`.
Optional keys that are unset are left out; `group` is written only when it
differs from `id`.

---

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