pub struct StructuredOutputParser { /* private fields */ }Expand description
Structured output parser
Parses the LLM’s key-value output (one key: value per line) into a HashMap.
Suited to scenarios where the LLM emits structured information in a non-JSON format.
§Format
The input format should be one key: value per line, e.g.:
姓名: 张三
年龄: 28
城市: 北京§Example
ⓘ
use langchainrust::output_parsers::StructuredOutputParser;
let parser = StructuredOutputParser::new();
let result = parser.parse("姓名: 张三\n年龄: 28").await?;
assert_eq!(result.get("姓名").unwrap(), "张三");Implementations§
Source§impl StructuredOutputParser
impl StructuredOutputParser
Sourcepub fn with_separator(separator: char) -> Self
pub fn with_separator(separator: char) -> Self
Creates a parser using a custom separator
Trait Implementations§
Source§impl BaseOutputParser<HashMap<String, String>> for StructuredOutputParser
impl BaseOutputParser<HashMap<String, String>> for StructuredOutputParser
Source§fn parse<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = OutputParserResult<HashMap<String, String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn parse<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = OutputParserResult<HashMap<String, String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Parses raw LLM output text into the target type
Source§fn get_format_instructions(&self) -> String
fn get_format_instructions(&self) -> String
Returns format instructions (to prompt the LLM to output in the expected format)
Source§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 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) Read moreSource§impl Default for StructuredOutputParser
impl Default for StructuredOutputParser
Source§impl Runnable<LLMResult, HashMap<String, String>> for StructuredOutputParser
impl Runnable<LLMResult, HashMap<String, String>> for StructuredOutputParser
Source§type Error = OutputParserError
type Error = OutputParserError
Error type.
Source§fn invoke<'life0, 'async_trait>(
&'life0 self,
input: LLMResult,
_config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, String>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn invoke<'life0, 'async_trait>(
&'life0 self,
input: LLMResult,
_config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, String>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Transforms single input to output. Read more
Source§fn stream<'life0, 'async_trait>(
&'life0 self,
input: LLMResult,
_config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<HashMap<String, String>, Self::Error>> + Send>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
input: LLMResult,
_config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<HashMap<String, String>, Self::Error>> + Send>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Streaming output - for real-time responses (LLM, etc). Read more
Source§fn batch<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<Input>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Output>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn batch<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<Input>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Output>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Batch processing - transforms multiple inputs to outputs. Read more
Source§fn batch_as_completed<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<Input>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<(usize, Output)>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn batch_as_completed<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<Input>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<(usize, Output)>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Batch processing that returns results in completion order. Read more
Source§fn transform<'life0, 'async_trait>(
&'life0 self,
input: Pin<Box<dyn Stream<Item = Result<Input, Self::Error>> + Send>>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Output, Self::Error>> + Send + '_>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn transform<'life0, 'async_trait>(
&'life0 self,
input: Pin<Box<dyn Stream<Item = Result<Input, Self::Error>> + Send>>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Output, Self::Error>> + Send + '_>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream-to-stream transformation - the core of LCEL streaming. Read more
Auto Trait Implementations§
impl Freeze for StructuredOutputParser
impl RefUnwindSafe for StructuredOutputParser
impl Send for StructuredOutputParser
impl Sync for StructuredOutputParser
impl Unpin for StructuredOutputParser
impl UnsafeUnpin for StructuredOutputParser
impl UnwindSafe for StructuredOutputParser
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<I, O, R> RunnableExt<I, O> for R
impl<I, O, R> RunnableExt<I, O> for R
Source§fn pipe<O2, R2>(self, other: R2) -> RunnableSequence<Input, O2>
fn pipe<O2, R2>(self, other: R2) -> RunnableSequence<Input, O2>
Pipe the output of this runnable into another runnable. Read more
Source§fn into_sequence(self) -> RunnableSequence<Input, Output>
fn into_sequence(self) -> RunnableSequence<Input, Output>
Create a
RunnableSequence from this runnable as a single step. Read moreSource§fn with_fallbacks<R>(
self,
fallbacks: Vec<R>,
) -> RunnableWithFallbacks<Input, Output>
fn with_fallbacks<R>( self, fallbacks: Vec<R>, ) -> RunnableWithFallbacks<Input, Output>
Add fallback runnables that are tried if this one fails. Read more
Source§fn with_retry(self, retry_config: RetryConfig) -> RunnableRetry<Input, Output>where
Input: Clone,
fn with_retry(self, retry_config: RetryConfig) -> RunnableRetry<Input, Output>where
Input: Clone,
Wrap this runnable with retry logic using exponential backoff. Read more
Source§fn configurable_alternatives<K, R>(
self,
which: impl Into<String>,
default_key: impl Into<String>,
alternatives: Vec<(K, R)>,
) -> RunnableConfigurable<Input, Output>
fn configurable_alternatives<K, R>( self, which: impl Into<String>, default_key: impl Into<String>, alternatives: Vec<(K, R)>, ) -> RunnableConfigurable<Input, Output>
Route between a default runnable and named alternatives at invoke time. Read more
Source§fn configurable_fields(self) -> RunnableConfigurableFields<Input, Output>
fn configurable_fields(self) -> RunnableConfigurableFields<Input, Output>
Override recognized config fields at invoke time from
config.configurable (Python’s Runnable.configurable_fields). Read more