pub trait BaseOutputParser<Output: Send + Sync + 'static>: Send + Sync {
// Required method
fn parse<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = OutputParserResult<Output>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn parse_with_retry<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
max_retries: usize,
) -> Pin<Box<dyn Future<Output = OutputParserResult<Output>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn get_format_instructions(&self) -> String { ... }
}Expand description
Core trait for output parsers
Every output parser must implement this trait.
Unlike Runnable, parse takes no config argument,
so it fits being called inside a Runnable.
Required Methods§
Provided Methods§
Sourcefn parse_with_retry<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
max_retries: usize,
) -> Pin<Box<dyn Future<Output = OutputParserResult<Output>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn parse_with_retry<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
max_retries: usize,
) -> Pin<Box<dyn Future<Output = OutputParserResult<Output>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Parsing with retry (default: genuinely retries max_retries times)
Calls parse repeatedly on the same text, at most
max_retries + 1 times. Retrying the same text only makes sense for
non-deterministic parsing (e.g. a parser that depends on the network /
external services); a deterministic parser that fails once will keep
failing, and the last error is returned. Parsers that need to correct
the input based on the failure reason should override this method.
Sourcefn get_format_instructions(&self) -> String
fn get_format_instructions(&self) -> String
Returns format instructions (to prompt the LLM to output in the expected format)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".