Skip to main content

Module validation

Module validation 

Source
Expand description

Structured input validation for the Skill contract.

Every skill declares a list of Rules in its Skill::validation_rules implementation. The dispatcher evaluates them after the arguments arrive and BEFORE the call body runs; on failure the call returns a structured {"validation_failed": [...]} payload describing exactly which fields broke which rules, so an LLM caller can correct itself without parsing English error strings.

The same rule tree can be surfaced through an introspection tool (see crate::describe) so a caller can audit the constraints up-front. It complements the JSON Schema that comes from schemars derives — JSON Schema tells the caller the shape (types, required fields), validation_rules tells it the domain constraints (range, mutual exclusion, allowed enum values, regex shape).

§Composability

Rules nest with All (AND), Any (OR), and Not. ExactlyOne and AtLeastOne over a set of field names express the common mutually-exclusive / “supply one of” patterns natively, so skills don’t have to roll their own. The Custom variant is the escape hatch for anything the declarative DSL can’t express.

Structs§

FieldViolation
One field-level constraint violation, structured for a caller to read.

Enums§

Rule
Declarative validation rule. Built once per skill (typically as a &'static [Rule]) so there’s no per-call allocation cost.
ValidationResult
Outcome of Skill::validate.

Functions§

evaluate
Evaluate every rule against the parsed arg object.
rules_to_json
Render a rule tree as a JSON shape suitable for an introspection tool.