Imp.Observability.Inspection (Imp v0.9.0)

Copy Markdown View Source

A deterministic, redacted debugging snapshot, as returned by Imp.Observability.inspect_artifact/2.

Inspection entries use a common shape across provider calls, tools, RLM actions, optimizer reports, predictions, and telemetry. Large payloads are replaced by bounded fingerprints so interactive debugging cannot accidentally copy an unbounded model response into the shell or logs.

Summary

Functions

Returns value as a term Jason can encode, deterministically.

Types

entry()

@type entry() :: %{source: atom(), sequence: pos_integer(), payload: term()}

t()

@type t() :: %Imp.Observability.Inspection{
  entries: [entry()],
  kind: atom(),
  status: atom(),
  summary: map()
}

Functions

json_safe(inspection)

@spec json_safe(term()) :: term()

Returns value as a term Jason can encode, deterministically.

Structs and maps with atom or UTF-8 string keys become maps with string keys; a map with other keys becomes %{"__imp_type__" => "map", "entries" => [[key, value], ...]} in a stable order. Tuples become lists, an improper list becomes %{"__imp_type__" => "improper_list", "head" => ..., "tail" => ...}, and atoms other than nil, true and false become strings.

A binary that is not valid UTF-8, as a value or as a map key, becomes %{"__imp_type__" => "binary", "bytes" => size}. Neither its content nor a digest of it is rendered: such bytes are most often key material, ciphertext or random values, and a digest of a short one gives it back by trying every candidate. Anything else that is not a number or a UTF-8 binary, such as a pid, a reference or a function, becomes its inspect/1 text.

Nothing is redacted here; pass a value through Imp.Redaction.redact/1 first when it may carry secrets.

iex> Imp.Observability.Inspection.json_safe(%{kind: :tool, args: {1, :a}})
%{"args" => [1, "a"], "kind" => "tool"}