Jido.AI.Validation (Jido AI v2.2.0)

Copy Markdown View Source

Validation utilities for Jido.AI runtime inputs.

This module centralizes prompt/input validation, callback validation, and resource-bound checks used across actions and strategies.

Summary

Functions

Returns the default callback timeout in milliseconds.

Returns the hard upper bound for max-turn validation.

Returns the maximum allowed general input length.

Returns the maximum allowed custom prompt length.

Validates prompt input and returns a sanitized version.

Validates and wraps callbacks with timeout protection.

Validates callback arity and type.

Validates custom prompts used for system-level behavior.

Validates and caps requested max-turn counts.

Validates prompt input without transforming it.

Validates generic string input with length and control-byte checks.

Types

callback()

@type callback() :: function()

prompt()

@type prompt() :: String.t()

validation_result()

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

Functions

callback_timeout()

@spec callback_timeout() :: integer()

Returns the default callback timeout in milliseconds.

max_hard_turns()

@spec max_hard_turns() :: integer()

Returns the hard upper bound for max-turn validation.

max_input_length()

@spec max_input_length() :: integer()

Returns the maximum allowed general input length.

max_prompt_length()

@spec max_prompt_length() :: integer()

Returns the maximum allowed custom prompt length.

validate_and_sanitize_prompt(prompt)

@spec validate_and_sanitize_prompt(prompt()) :: {:ok, prompt()} | {:error, atom()}

Validates prompt input and returns a sanitized version.

validate_and_wrap_callback(callback, opts \\ [])

@spec validate_and_wrap_callback(
  callback(),
  keyword()
) :: {:ok, callback()} | {:error, atom()}

Validates and wraps callbacks with timeout protection.

validate_callback(callback)

@spec validate_callback(callback()) :: validation_result()

Validates callback arity and type.

Wrapped callbacks are invoked with a single argument, so only arity-1 callbacks are valid.

validate_custom_prompt(custom_prompt, opts \\ [])

@spec validate_custom_prompt(
  prompt(),
  keyword()
) :: {:ok, prompt()} | {:error, atom()}

Validates custom prompts used for system-level behavior.

validate_max_turns(max_turns)

@spec validate_max_turns(integer()) :: {:ok, integer()} | {:error, atom()}

Validates and caps requested max-turn counts.

validate_prompt(prompt)

@spec validate_prompt(prompt()) :: validation_result()

Validates prompt input without transforming it.

validate_string(input, opts \\ [])

@spec validate_string(
  String.t() | nil,
  keyword()
) :: {:ok, String.t()} | {:error, atom()}

Validates generic string input with length and control-byte checks.