pub struct StructuredOutputParser<T: DeserializeOwned> { /* private fields */ }Expand description
Parser that deserialises JSON text to a typed struct.
Use this when you have a specific Rust type annotated with #[derive(Deserialize)]
that you want to parse model output into.
§Examples
use serde::Deserialize;
use synwire_core::output_parsers::{OutputParser, StructuredOutputParser};
#[derive(Deserialize, Debug, PartialEq)]
struct Person {
name: String,
age: u32,
}
let parser = StructuredOutputParser::<Person>::new();
let result = parser.parse(r#"{"name": "Alice", "age": 30}"#).unwrap();
assert_eq!(result.name, "Alice");
assert_eq!(result.age, 30);Implementations§
Source§impl<T: DeserializeOwned> StructuredOutputParser<T>
impl<T: DeserializeOwned> StructuredOutputParser<T>
Source§impl<T: DeserializeOwned + Send + Sync> StructuredOutputParser<T>
impl<T: DeserializeOwned + Send + Sync> StructuredOutputParser<T>
Sourcepub fn parse_with_retry_context(
&self,
text: &str,
) -> Result<T, (SynwireError, String)>
pub fn parse_with_retry_context( &self, text: &str, ) -> Result<T, (SynwireError, String)>
Parse with a validation error message for retry.
On success, returns the parsed value. On failure, returns both the original error and a formatted context string suitable for inclusion in a retry prompt.
§Errors
Returns a tuple of (SynwireError, retry context String) when
parsing fails.
Trait Implementations§
Source§impl<T: DeserializeOwned> Default for StructuredOutputParser<T>
impl<T: DeserializeOwned> Default for StructuredOutputParser<T>
Source§impl<T: DeserializeOwned + Send + Sync> OutputParser for StructuredOutputParser<T>
impl<T: DeserializeOwned + Send + Sync> OutputParser for StructuredOutputParser<T>
Auto Trait Implementations§
impl<T> Freeze for StructuredOutputParser<T>
impl<T> RefUnwindSafe for StructuredOutputParser<T>where
T: RefUnwindSafe,
impl<T> Send for StructuredOutputParser<T>where
T: Send,
impl<T> Sync for StructuredOutputParser<T>where
T: Sync,
impl<T> Unpin for StructuredOutputParser<T>where
T: Unpin,
impl<T> UnsafeUnpin for StructuredOutputParser<T>
impl<T> UnwindSafe for StructuredOutputParser<T>where
T: UnwindSafe,
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