Skip to main content

Validator

Struct Validator 

Source
pub struct Validator {
    pub limits: ValidationLimits,
}
Expand description

Validates AgentOutput fields against configurable limits.

Uses clean_title for normalizing finding titles before length validation, and configurable limits for field lengths and counts.

Fields§

§limits: ValidationLimits

Active validation limits.

Implementations§

Source§

impl Validator

Source

pub fn new() -> Self

Creates a validator with default limits.

Source

pub fn with_limits(limits: ValidationLimits) -> Self

Creates a validator with custom limits.

Source

pub fn validate(&self, output: &AgentOutput) -> Result<(), MagiError>

Validates an AgentOutput, returning on first failure.

Checks in order: confidence, summary, reasoning, recommendation, findings. Returns MagiError::Validation with a descriptive message on failure.

Source

pub fn validate_mut(&self, output: &mut AgentOutput) -> Result<(), MagiError>

Validates output in place, replacing each finding’s title with its cleaned form (see clean_title) before length validation.

This is the preferred entry point for pipelines that parse LLM responses, because it ensures downstream code sees titles in the canonical cleaned form used by the consensus engine.

§Atomicity

This method is atomic on error: it cleans and validates all finding titles into a temporary buffer before committing any mutation to output. If any validation check fails, output is left completely unchanged — no partial title cleaning occurs.

§Errors

Returns MagiError::Validation on the first field that fails validation. Validation order: confidence → summary → reasoning → recommendation → findings (count, then each cleaned title/detail). On error, output is not modified.

Trait Implementations§

Source§

impl Default for Validator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.