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

Copy Markdown View Source

A set of nous.guard_case/1 cases (Nous.Eval.Guard.Case) loaded from JSONL, with its manifest and content hash.

{:ok, ds} = Nous.Eval.Guard.Dataset.load("test/fixtures/guard")
:ok = Nous.Eval.Guard.Dataset.validate(ds, licences: :in_repo, pii: true)

load/2 takes a .jsonl file or a directory (every *.jsonl directly in it). A directory with a *.manifest.json (schema nous.guard_dataset/1) is checked against it: the listed files must be exactly the JSONL files present, and each file's canonical hash (Nous.Eval.Guard.Hygiene.sha256/1) must match. Loading fails closed on the first error: a malformed line, an unknown key, a duplicate id or a manifest mismatch.

Manifest

{"schema": "nous.guard_dataset/1", "name": "nous-builtin-guard", "version": "2026.11.0",
 "case_schema": "nous.guard_case/1",
 "files": [{"path": "user_input.jsonl", "sha256": "sha256:...", "cases": 640}],
 "counts": {"user_input": {"tune": {"block": 120, "allow": 180}}},
 "split_seed": "nous-guard-v1",
 "sources": [{"id": "deepset/prompt-injections", "revision": "4f61ecb0...", "license": "Apache-2.0"}],
 "accepted_terms": []}

write/3 writes a dataset in this layout (one canonical JSONL file per surface, plus one per deterministic kind) with its manifest.

Summary

Functions

The cases matching every given filter: :kind, :surface, :split, :label (each one value or a list), :labelled (true drops label: null), :certifiable (true keeps Nous.Eval.Guard.Case.certifiable?/1 cases).

Loads a JSONL file or a directory of them (see the moduledoc).

The manifest for cases written as files ([{path, cases}]).

The manifest schema id ("nous.guard_dataset/1").

A dataset from cases already built in Elixir. Ids must be unique.

Parses one JSONL file of guard cases. Blank lines are skipped; errors name the file and line.

Checks the dataset invariants and returns every problem found.

Writes cases to dir as canonical JSONL (<surface>.jsonl per surface, <kind>.jsonl per deterministic kind) plus <name>.manifest.json. Returns the manifest. Options as manifest/2; :name is required.

Types

t()

@type t() :: %Nous.Eval.Guard.Dataset{
  cases: [Nous.Eval.Guard.Case.t()],
  hash: String.t(),
  manifest: map() | nil,
  name: String.t() | nil,
  source: Path.t() | nil,
  version: String.t() | nil
}

Functions

cases(dataset, filters \\ [])

@spec cases(t(), keyword()) :: [Nous.Eval.Guard.Case.t()]

The cases matching every given filter: :kind, :surface, :split, :label (each one value or a list), :labelled (true drops label: null), :certifiable (true keeps Nous.Eval.Guard.Case.certifiable?/1 cases).

load(path, opts \\ [])

@spec load(Path.t(), keyword()) :: {:ok, t()} | {:error, String.t()}

Loads a JSONL file or a directory of them (see the moduledoc).

Options: :verify_manifest (default true; a directory without a manifest loads unverified either way).

manifest(files, opts \\ [])

@spec manifest([{String.t(), [Nous.Eval.Guard.Case.t()]}], keyword()) :: map()

The manifest for cases written as files ([{path, cases}]).

Options: :name, :version, :split_seed, :sources (list of maps), :accepted_terms (list of source ids).

manifest_schema()

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

The manifest schema id ("nous.guard_dataset/1").

new(cases, opts \\ [])

@spec new([Nous.Eval.Guard.Case.t()], keyword()) :: {:ok, t()} | {:error, String.t()}

A dataset from cases already built in Elixir. Ids must be unique.

Options: :name, :version.

parse_file(path)

@spec parse_file(Path.t()) :: {:ok, [Nous.Eval.Guard.Case.t()]} | {:error, String.t()}

Parses one JSONL file of guard cases. Blank lines are skipped; errors name the file and line.

validate(dataset, opts \\ [])

@spec validate(t(), keyword()) :: :ok | {:error, [String.t()]}

Checks the dataset invariants and returns every problem found.

Always: unique ids; no exact duplicate (Nous.Eval.Guard.Hygiene.dedup_key/1) within a surface; no group in two splits; every split of a surface holds both labels (labelled classifier cases).

Options:

write(cases, dir, opts)

@spec write([Nous.Eval.Guard.Case.t()], Path.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Writes cases to dir as canonical JSONL (<surface>.jsonl per surface, <kind>.jsonl per deterministic kind) plus <name>.manifest.json. Returns the manifest. Options as manifest/2; :name is required.