Imp.AdapterParseError exception (Imp v0.5.0)

Copy Markdown View Source

A completion that could not be read as the signature's outputs.

Adapters return {:error, %Imp.AdapterParseError{}} from parse/3, and Imp.Predict returns the same struct when no completion could be parsed, after any fallback it tried. :kind says what was wrong:

  • :malformed — the completion is not in the adapter's format at all: no JSON object for the JSON adapter, XML that does not parse, a one-field answer that is not the exact value the field allows.
  • :missing_fields — required output fields are absent. :reason is the list of their names.
  • :invalid_fields — every field is present but some value does not fit its declared type. :reason is the fields that were read.
  • :unsupported_output — the LM returned something no adapter reads as a completion (not text or a map), or no completion at all.
  • :other — a custom adapter returned an error that is not this struct; :reason is that error.

An adapter that sends a request of its own, such as Imp.Adapter.TwoStep, does not report that request's failure as a parse error: the call returns the Imp.LMError (or {:lm_failed, client, reason}) itself.

:message is the feedback a retry shows the model. Imp.Predict also fills :trace (the redacted messages, the raw completion, and which output fields were read) and, for an n > 1 call, :completion_index, the position of the first completion that failed.

A parse failure is not retryable in the sense of Imp.Errors.retryable?/1: sending the same request again is not what fixes it.

Summary

Types

kind()

@type kind() ::
  :malformed | :missing_fields | :invalid_fields | :unsupported_output | :other

t()

@type t() :: %Imp.AdapterParseError{
  __exception__: true,
  completion_index: non_neg_integer() | nil,
  kind: kind(),
  message: String.t() | nil,
  reason: term(),
  trace: map() | nil
}