CrucibleIR.Validation (CrucibleIR v0.3.0)
View SourceValidation helpers for IR structs.
This module provides functions to validate CrucibleIR data structures and ensure they meet the required constraints before being used in experiments.
Functions
validate/1- Validates a struct, returns{:ok, struct}or{:error, errors}valid?/1- Returnstrueif struct is valid,falseotherwiseerrors/1- Returns list of validation errors
Validation here is structural only. Stage option validation and execution semantics belong to domain packages, not CrucibleIR.
Examples
iex> alias CrucibleIR.{Experiment, BackendRef, StageDef}
iex> exp = %Experiment{
...> id: :test,
...> backend: %BackendRef{id: :gpt4},
...> pipeline: [%StageDef{name: :run}]
...> }
iex> CrucibleIR.Validation.valid?(exp)
true
iex> alias CrucibleIR.BackendRef
iex> backend = %BackendRef{id: nil}
iex> {:error, errors} = CrucibleIR.Validation.validate(backend)
iex> "id must be a non-nil atom" in errors
true
Summary
Functions
Returns a list of validation errors for the struct.
Returns true if the struct is valid, false otherwise.
Validates a struct and returns {:ok, struct} if valid or {:error, errors} if invalid.
Functions
Returns a list of validation errors for the struct.
Returns an empty list if the struct is valid.
Parameters
struct- Any CrucibleIR struct to check
Examples
iex> alias CrucibleIR.BackendRef
iex> backend = %BackendRef{id: :gpt4}
iex> CrucibleIR.Validation.errors(backend)
[]
iex> alias CrucibleIR.BackendRef
iex> backend = %BackendRef{id: nil}
iex> errors = CrucibleIR.Validation.errors(backend)
iex> length(errors) > 0
true
Returns true if the struct is valid, false otherwise.
Parameters
struct- Any CrucibleIR struct to check
Examples
iex> alias CrucibleIR.BackendRef
iex> backend = %BackendRef{id: :gpt4}
iex> CrucibleIR.Validation.valid?(backend)
true
iex> alias CrucibleIR.BackendRef
iex> backend = %BackendRef{id: nil}
iex> CrucibleIR.Validation.valid?(backend)
false
Validates a struct and returns {:ok, struct} if valid or {:error, errors} if invalid.
Parameters
struct- Any CrucibleIR struct to validate
Returns
{:ok, struct}- If the struct is valid{:error, [error_message]}- If the struct has validation errors
Examples
iex> alias CrucibleIR.BackendRef
iex> backend = %BackendRef{id: :gpt4}
iex> {:ok, ^backend} = CrucibleIR.Validation.validate(backend)
{:ok, %CrucibleIR.BackendRef{id: :gpt4}}
iex> alias CrucibleIR.BackendRef
iex> backend = %BackendRef{id: nil}
iex> {:error, _errors} = CrucibleIR.Validation.validate(backend)