Spectre.Router.Receipt (Spectre v0.3.0)

Copy Markdown View Source

Privacy-safe summary of one router-only evaluation.

A receipt records the selected route, sanitized provider-call outcomes and durations, and whether an LLM adapter was actually invoked. It deliberately excludes input text, prompts, model output, candidate matches, and handlers so evaluation artifacts can be shared without silently becoming conversation logs.

Summary

Functions

Builds a receipt from a completed routing context.

Builds an error receipt when the router pipeline cannot complete.

Types

attempt()

@type attempt() :: %{
  :provider => atom(),
  :result => atom(),
  optional(:label) => atom() | nil,
  optional(:reason) => atom() | nil
}

candidate_summary()

@type candidate_summary() :: %{
  :provider => atom(),
  :label => atom() | nil,
  :accepted? => boolean(),
  :score => number() | nil,
  :margin => number() | nil,
  :strength => atom(),
  optional(:eligible?) => boolean(),
  optional(:winner?) => boolean(),
  optional(:rejection_reason) => atom() | nil,
  optional(:required) => map()
}

outcome()

@type outcome() :: :route | :clarify | :unknown | :error

provider_call()

@type provider_call() :: %{
  :provider => atom(),
  :outcome => atom(),
  :duration_us => non_neg_integer(),
  :invoked? => boolean(),
  optional(:purpose) => atom()
}

t()

@type t() :: %Spectre.Router.Receipt{
  accepted?: boolean(),
  arbitration: map() | nil,
  attempts: [attempt()],
  candidates: [candidate_summary()],
  duration_us: non_neg_integer(),
  error: atom() | nil,
  label: atom() | nil,
  llm_called?: boolean(),
  outcome: outcome(),
  provider_calls: [provider_call()],
  scope: Spectre.Definition.scope() | nil,
  strategy: atom() | nil,
  trace_codes: [atom()]
}

Functions

from_context(context, duration_us)

@spec from_context(Spectre.Router.Context.t(), non_neg_integer()) :: t()

Builds a receipt from a completed routing context.

from_error(reason, duration_us)

@spec from_error(term(), non_neg_integer()) :: t()

Builds an error receipt when the router pipeline cannot complete.