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

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

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

# `t`

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

# `cases`

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

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

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

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

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

# `new`

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

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

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

  * `:licences` - `:in_repo` or `:fetch` (`Nous.Eval.Guard.Hygiene.licence_violations/2`);
    default none, so an app can load data of any licence for itself
  * `:pii` - `true` runs `Nous.Eval.Guard.Hygiene.pii_lint/1`
  * `:near_duplicates` - `true` also refuses near-duplicate pairs that
    cross splits (O(n²) per surface up to the MinHash threshold)

# `write`

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

---

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