Cantrip.LLM.Response (Cantrip v1.3.3)

Copy Markdown View Source

This is the response shape every LLM provider answer becomes before the runtime reads it. If you implement Cantrip.LLM, prefer returning this shape; raw provider maps are accepted only when they satisfy the same boundary contract.

Normalized provider response boundary object.

LLM adapters may speak provider-specific data shapes internally, but the rest of Cantrip consumes this struct. Required keys are enforced at construction so provider contract drift fails at the boundary instead of being papered over by downstream Map.get/3 defaults.

Summary

Types

t()

@type t() :: %Cantrip.LLM.Response{
  content: String.t() | nil,
  raw_response: term(),
  stop_reason: atom() | nil,
  tool_calls: [map()],
  usage: map()
}

Functions

new(response)

@spec new(map() | t()) :: {:ok, t()} | {:error, String.t()}