GEPA.Adapters.Confidence (GEPA v0.3.0)

Copy Markdown View Source

Logprob-aware classification adapter.

This ports the upstream ConfidenceAdapter concept while keeping the Elixir adapter mechanism. The adapter asks a model for structured JSON, extracts a target field, checks correctness against :answer, and optionally applies a confidence penalty using joint field logprob metadata.

The optional :logprob_extractor seam lets tests or provider-specific code supply logprob data without depending on a Python package. It may return:

  • a number joint logprob
  • %{joint_logprob: number, top_logprobs: list}
  • %{"joint_logprob" => number, "top_logprobs" => list}

Summary

Functions

Build human-readable feedback for reflection.

Extract a nested field from a decoded JSON map.

Types

data_inst()

@type data_inst() :: map()

t()

@type t() :: %GEPA.Adapters.Confidence{
  failure_score: float(),
  field_path: String.t() | [String.t() | atom()],
  logprob_extractor: function() | nil,
  model: term(),
  normalizer: function() | nil,
  prompt_template: String.t() | nil,
  schema: map() | keyword() | nil,
  scoring_strategy: term()
}

Functions

build_feedback(trace)

@spec build_feedback(map()) :: String.t()

Build human-readable feedback for reflection.

extract_answer_from_json(text, field_path)

@spec extract_answer_from_json(map() | String.t(), String.t() | [String.t() | atom()]) ::
  term()

Extract a nested field from a decoded JSON map.

new(opts \\ [])

@spec new(keyword() | map()) :: t()