Tune.Signature (Tune v0.5.0)

Copy Markdown View Source

Ordered, typed input and output fields plus task instructions.

{:ok, signature} =
  Tune.Signature.new(
    instructions: "Classify the support ticket.",
    inputs: [ticket: Zoi.string(description: "Customer message")],
    outputs: [label: Zoi.enum(["billing", "bug", "other"])]
  )

Field names are normalized to strings once. Field order is preserved in every prompt format. Input and output values are string-keyed maps. Instructions are the only tunable part of a signature.

Summary

Functions

Returns input field names in declared order.

Builds a signature.

Normalizes and validates input values.

Returns output field names in declared order.

Returns a signature with replaced instructions.

Validates a string-keyed output map against the declared output schema.

Types

t()

@type t() :: %Tune.Signature{
  input_schema: Zoi.schema(),
  inputs: [Tune.Field.t()],
  instructions: String.t(),
  output_schema: Zoi.schema(),
  outputs: [Tune.Field.t()]
}

Functions

input_names(signature)

@spec input_names(t()) :: [String.t()]

Returns input field names in declared order.

new(opts)

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

Builds a signature.

Options:

  • :inputs - nonempty list of field specifications
  • :outputs - nonempty list of field specifications
  • :instructions - task instructions; defaults to a sentence naming the fields

normalize_inputs(signature, values)

@spec normalize_inputs(t(), map()) :: {:ok, map()} | {:error, Exception.t()}

Normalizes and validates input values.

Top-level keys may be declared strings or the matching trusted atoms. Unknown keys, missing keys, and atom/string duplicates are errors. No atoms are created.

output_names(signature)

@spec output_names(t()) :: [String.t()]

Returns output field names in declared order.

put_instructions(signature, instructions)

@spec put_instructions(t(), String.t()) :: {:ok, t()} | {:error, Exception.t()}

Returns a signature with replaced instructions.

validate_outputs(signature, values)

@spec validate_outputs(t(), map()) :: {:ok, map()} | {:error, [Zoi.Error.t()]}

Validates a string-keyed output map against the declared output schema.