Nous.Eval.Guard.Case (nous v0.21.1)

Copy Markdown View Source

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").

{"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.

Summary

Functions

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).

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

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

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

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

The surfaces a classifier case may name.

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.

Types

kind()

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

label()

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

split()

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

surface()

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

t()

@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()

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

Functions

acceptable(case)

@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?(case)

@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(c)

@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(map)

@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()

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

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

surfaces()

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

The surfaces a classifier case may name.

to_map(c)

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