Imp.Signature.Field (Imp v0.5.0)

Copy Markdown View Source

Metadata and construction rules for one signature field.

Prefer the compact signature DSL for ordinary fields. Structured signatures accept each field as an atom, a "name: type" string, {name, options}, or a map. A field map accepts atom or string versions of these keys:

  • name (required) and type (an atom or string, default :string)
  • kind (:input or :output, normally supplied by the signature)
  • desc and prefix
  • default, optional, constraints, and language
  • metadata for additional JSON-friendly field metadata

Nested types use the string grammar, for example "array[string]" or "array[object]"; tuple forms such as {:array, :string} are not accepted. Constraints are maps such as %{enum: ["red", "blue"]}, %{minimum: 0}, or %{maximum: 1}, keyed by their JSON Schema names; min and max raise. default fills an absent value. optional: true permits omission and represents it as nil.

iex> field = Imp.Signature.Field.new(%{
...>   name: :tags,
...>   type: "array[string]",
...>   optional: true
...> }, :output)
iex> {field.name, field.type, field.metadata.optional}
{:tags, "array[string]", true}

Field declarations describe both sides of the program contract, but input value type mismatches are warning-only at call time for DSPy compatibility. Required input presence and all parsed outputs are enforced.

Summary

Functions

Adds output-validation constraints to a field.

Serializes a field to JSON-friendly data.

Loads a field produced by dump/1.

Builds a field from an existing field, name, typed name, tuple, or map.

Marks a field optional and nullable.

Types

t()

@type t() :: %Imp.Signature.Field{
  desc: String.t() | nil,
  kind: :input | :output,
  metadata: map(),
  name: atom() | String.t(),
  prefix: String.t() | nil,
  type: atom() | String.t()
}

Functions

constrained(field, constraints)

Adds output-validation constraints to a field.

dump(field)

Serializes a field to JSON-friendly data.

load(map)

Loads a field produced by dump/1.

new(field, kind)

Builds a field from an existing field, name, typed name, tuple, or map.

optional(field)

Marks a field optional and nullable.