ExMaude.AI.Validator (ExMaude v0.3.0)

View Source

Validates AI rule structures before encoding to Maude.

Companion to ExMaude.IoT.Validator. Catches shape errors, unsupported predicate types, and obviously-malformed values before they reach the Maude port worker. Validation here is cheap; rejecting at this layer avoids the cost of a Maude round trip for a malformed rule.

An AI rule is a map with these required fields:

  • :id — non-empty string
  • :agent_id{tenant_id :: String.t(), agent_name :: String.t()}
  • :trigger — predicate (see Encoder docs for predicate shapes)
  • :invocations — list of tool invocations (may be empty)

Optional fields:

  • :capability_grants — list of {:cap, name, shape} or bare strings
  • :authority_required — non-negative integer (default 0)
  • :priority — non-negative integer (default 1)

Summary

Functions

Validates a single AI rule.

Validates a list of rules. Returns :ok if all rules pass, or {:error, %{rule_id => errors}} mapping failing rule ids to their error lists.

Functions

validate_rule(rule)

@spec validate_rule(term()) :: :ok | {:error, [String.t()]}

Validates a single AI rule.

Returns :ok on success, or {:error, [error_msg]} listing all validation failures.

Examples

iex> ExMaude.AI.Validator.validate_rule(%{
...>   id: "r1",
...>   agent_id: {"acme", "ag-1"},
...>   trigger: {:always},
...>   invocations: []
...> })
:ok

iex> ExMaude.AI.Validator.validate_rule(%{})
{:error,
 [
   "missing required field: id",
   "missing required field: agent_id",
   "missing required field: trigger",
   "missing required field: invocations"
 ]}

iex> rule = %{
...>   id: "r1",
...>   agent_id: {"acme", "ag-1"},
...>   trigger: {:contains, "x", "y"},
...>   invocations: []
...> }
...>
...> ExMaude.AI.Validator.validate_rule(rule)
{:error,
 ["trigger: :contains is unverifiable in ai-rules.maude (route to string-match safety net)"]}

validate_rules(rules)

@spec validate_rules([term()]) ::
  :ok | {:error, %{required(String.t()) => [String.t()]}}

Validates a list of rules. Returns :ok if all rules pass, or {:error, %{rule_id => errors}} mapping failing rule ids to their error lists.