Nous.Eval.Scorer behaviour (nous v0.21.1)

Copy Markdown View Source

Behaviour for eval scorers.

A scorer turns one sample (Nous.Eval.ScoreInput) into one or more Nous.Eval.Scores, a skip, or an error:

  • {:ok, score | [score]} - a verdict

  • {:skip, reason} - the scorer does not apply to this sample; excluded from its metrics. A required scorer may only skip when declared skippable: true, otherwise the skip is an :invalid_config error
  • {:error, %Nous.Eval.ScorerError{}} - the instrument failed

init/1 runs once per eval run and validates options; unknown options are an error. Scorers run under a supervisor with a time limit: a raise or timeout becomes a Nous.Eval.ScorerError and never discards another scorer's result.

describe/1 (optional) returns the configuration that identifies the scorer in the run fingerprint (for an LLM judge: model, prompt hash, scale). kind/0 (optional, default :deterministic) marks scorers that call a model as :model_graded. option_keys/0 (optional) lists the options a dataset file (YAML/JSONL) may set; a scorer without it cannot be configured from a file. init/1 must accept the string forms of its enum-valued options ("superset" for :superset), because file values are never turned into atoms.

content/0 (optional, default :required) declares whether the scorer reads content - the agent's input or output, messages, tool arguments or results, error text - or only the trace skeleton (ids, timings, tokens, cost, tool names and outcomes, guard verdicts). Nous.Eval.Online refuses to start a scorer that reads content under redact: :drop_content, where it would score empty values.

Referencing scorers from dataset files

YAML and JSONL name scorers by string, resolved with resolve/2 through a fixed table of built-ins plus the application's own table:

config :nous, :eval_scorers, %{"house_style" => MyApp.Eval.HouseStyle}

An unknown name or option is an error; nothing in a file becomes an atom.

Summary

Functions

Resolves a scorer named in a dataset file into a Spec.

Types

result()

@type result() ::
  {:ok, Nous.Eval.Score.t() | [Nous.Eval.Score.t()]}
  | {:skip, String.t()}
  | {:error, Nous.Eval.ScorerError.t()}

Callbacks

content()

(optional)
@callback content() :: :required | :none

describe(config)

(optional)
@callback describe(config :: term()) :: map()

id()

@callback id() :: String.t()

init(opts)

@callback init(opts :: keyword()) :: {:ok, config :: term()} | {:error, term()}

kind()

(optional)
@callback kind() :: :deterministic | :model_graded

option_keys()

(optional)
@callback option_keys() :: [atom()]

score(t, config)

@callback score(Nous.Eval.ScoreInput.t(), config :: term()) :: result()

Functions

resolve(name, opts \\ %{})

@spec resolve(String.t(), map()) ::
  {:ok, Nous.Eval.Scorer.Spec.t()} | {:error, String.t()}

Resolves a scorer named in a dataset file into a Spec.

name is looked up in the built-in table, then in config :nous, :eval_scorers. opts is the string-keyed map from the file: "required", "weight" and "skippable" set the composition, every other key must be one of the scorer's option_keys/0. Option values are passed through unchanged; the scorer's init/1 validates them.