LlmCore.Structured.Validator (llm_core v0.3.0)

Copy Markdown View Source

Normalizes schema declarations and validates decoded structured data.

The validator intentionally supports a small but extensible surface:

  • Function schemas – a single-arity validator function
  • Module schemas – modules that export validate/1, cast/1, from_map/1, or changeset/2
  • Map schemas – %{required: [...], optional: [...]} helpers or maps that enumerate fields
  • List schemas – treated as a list of required keys

When no schema is provided, the decoded value is returned verbatim.

Summary

Functions

Validates the decoded payload against the supplied schema.

Types

result()

@type result() :: {:ok, term()} | {:error, term()}

schema()

@type schema() :: module() | map() | [atom() | String.t()] | (map() -> result()) | nil

Functions

validate(value, schema, opts)

@spec validate(term(), schema(), keyword()) :: result()

Validates the decoded payload against the supplied schema.