Jido.Action.Schema (Jido Action v2.0.0-rc.0)
View SourceUnified schema validation interface supporting both NimbleOptions and Zoi.
This adapter provides a consistent API for:
- Schema validation
- Key introspection
- Error formatting
- JSON Schema generation (for AI tools)
Summary
Functions
Formats validation errors into Jido.Action.Error structs.
Extracts all known keys from a schema.
Detects the type of schema.
Converts a schema to JSON Schema format for AI tools.
Validates data against a schema.
Validates a schema value for use in configuration.
Types
@type t() :: NimbleOptions.schema() | struct() | []
Functions
@spec format_error(term(), String.t(), module()) :: Jido.Action.Error.InvalidInputError.t()
Formats validation errors into Jido.Action.Error structs.
Parameters
error- The error from validation (NimbleOptions.ValidationError, Zoi.Error, or list)context- Context string describing where the error occurredmodule- The module where the error occurred
Returns
Jido.Action.Error.InvalidInputError.t()- Formatted error struct
Extracts all known keys from a schema.
Parameters
schema- NimbleOptions schema or Zoi schema
Returns
- List of atom keys defined in the schema
@spec schema_type(t()) :: :nimble | :zoi | :empty | :unknown
Detects the type of schema.
Returns :nimble for NimbleOptions keyword list schemas, :zoi for Zoi schemas,
:empty for empty lists, or :unknown for unsupported types.
Converts a schema to JSON Schema format for AI tools.
For NimbleOptions schemas, converts to OpenAI-compatible JSON Schema. For Zoi schemas, uses Zoi's built-in JSON Schema conversion.
Parameters
schema- NimbleOptions schema or Zoi schema
Returns
- Map representing the JSON Schema
Validates data against a schema.
For NimbleOptions schemas, returns {:ok, map()} with validated data as a map.
For Zoi schemas, returns {:ok, struct()} with the validated struct.
For empty schemas, returns the data unchanged.
Parameters
schema- NimbleOptions schema (keyword list) or Zoi schemadata- Data to validate (map or keyword list)
Returns
{:ok, validated_data}- Validation succeeded{:error, error}- Validation failed
Validates a schema value for use in configuration.
Used during compilation to ensure schema configuration is valid.
Parameters
value- The schema value to validate_opts- Options (unused, for Zoi refine compatibility)
Returns
:ok- Schema is valid{:error, message}- Schema is invalid