pub struct StructuredValidator { /* private fields */ }Expand description
Structured output validator: schema validation of the model’s answer + independent retry budget + feedback messages.
Used by self-implemented Agents wiring up typed output
(TypedAgent): call
validate each round inside the loop,
and the component owns the budget counting — user code no longer writes
the “validate → count → check limit” boilerplate.
Budget semantics: up to max_retries retries after a failed validation;
the max_retries + 1-th failure returns
Exhausted.
§Examples
use molo::agent::{StructuredOutcome, StructuredValidator};
let schema = serde_json::json!({
"type": "object",
"properties": { "city": { "type": "string" } },
"required": ["city"],
});
let mut validator = StructuredValidator::new(schema, 3);
assert!(matches!(validator.validate("bad"), StructuredOutcome::Retry { .. }));
assert!(matches!(
validator.validate(r#"{"city":"Beijing"}"#),
StructuredOutcome::Passed
));Implementations§
Source§impl StructuredValidator
impl StructuredValidator
Sourcepub fn new(schema: Value, max_retries: usize) -> StructuredValidator
pub fn new(schema: Value, max_retries: usize) -> StructuredValidator
Construct with a schema and a retry budget; max_retries has the
same semantics as
AgentConfig::max_structured_retries
(the built-in assembly defaults to 3).
Trait Implementations§
Source§impl Clone for StructuredValidator
impl Clone for StructuredValidator
Source§fn clone(&self) -> StructuredValidator
fn clone(&self) -> StructuredValidator
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StructuredValidator
impl Debug for StructuredValidator
impl Eq for StructuredValidator
Source§impl PartialEq for StructuredValidator
impl PartialEq for StructuredValidator
impl StructuralPartialEq for StructuredValidator
Auto Trait Implementations§
impl Freeze for StructuredValidator
impl RefUnwindSafe for StructuredValidator
impl Send for StructuredValidator
impl Sync for StructuredValidator
impl Unpin for StructuredValidator
impl UnsafeUnpin for StructuredValidator
impl UnwindSafe for StructuredValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.