pub struct StrOutputParser { /* private fields */ }Expand description
Extract text content from model outputs as a string.
Converts model outputs (such as AIMessage or AIMessageChunk objects)
into plain text strings. It’s the simplest output parser and is useful
when you need string responses for downstream processing, display, or storage.
Supports streaming, yielding text chunks as they’re generated by the model.
§Example
ⓘ
use agent_chain_core::output_parsers::StrOutputParser;
let parser = StrOutputParser::new();
// Parse a simple string
let result = parser.parse("Hello, world!").unwrap();
assert_eq!(result, "Hello, world!");Implementations§
Source§impl StrOutputParser
impl StrOutputParser
Sourcepub fn is_lc_serializable() -> bool
pub fn is_lc_serializable() -> bool
Returns true as this class is serializable.
Sourcepub fn get_lc_namespace() -> Vec<&'static str>
pub fn get_lc_namespace() -> Vec<&'static str>
Get the namespace of the LangChain object.
Returns ["langchain", "schema", "output_parser"]
Trait Implementations§
Source§impl BaseOutputParser for StrOutputParser
impl BaseOutputParser for StrOutputParser
Source§fn parser_type(&self) -> &str
fn parser_type(&self) -> &str
Return the output parser type for serialization.
Source§fn aparse<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn aparse<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Async parse a single string model output into some structure. Read more
Source§fn parse_result(
&self,
result: &[Generation],
_partial: bool,
) -> Result<Self::Output>
fn parse_result( &self, result: &[Generation], _partial: bool, ) -> Result<Self::Output>
Parse a list of candidate model
Generation objects into a specific format. Read moreSource§fn aparse_result<'life0, 'life1, 'async_trait>(
&'life0 self,
result: &'life1 [Generation],
partial: bool,
) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn aparse_result<'life0, 'life1, 'async_trait>(
&'life0 self,
result: &'life1 [Generation],
partial: bool,
) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Async parse a list of candidate model
Generation objects into a specific format.Source§fn parse_with_prompt(
&self,
completion: &str,
_prompt: &dyn PromptValue,
) -> Result<Self::Output>
fn parse_with_prompt( &self, completion: &str, _prompt: &dyn PromptValue, ) -> Result<Self::Output>
Parse the output of an LLM call with the input prompt for context. Read more
Source§fn get_format_instructions(&self) -> Result<String>
fn get_format_instructions(&self) -> Result<String>
Instructions on how the LLM output should be formatted. Read more
Source§fn invoke(
&self,
input: BaseMessage,
_config: Option<RunnableConfig>,
) -> Result<Self::Output>
fn invoke( &self, input: BaseMessage, _config: Option<RunnableConfig>, ) -> Result<Self::Output>
Invoke the parser on input. Read more
Source§impl BaseTransformOutputParser for StrOutputParser
impl BaseTransformOutputParser for StrOutputParser
Source§fn parse_generation(&self, generation: &Generation) -> Result<Self::Output>
fn parse_generation(&self, generation: &Generation) -> Result<Self::Output>
Parse a generation into the output type.
Source§fn transform<'a>(
&'a self,
input: BoxStream<'a, StringOrMessage>,
) -> BoxStream<'a, Result<Self::Output>>where
Self::Output: 'a,
fn transform<'a>(
&'a self,
input: BoxStream<'a, StringOrMessage>,
) -> BoxStream<'a, Result<Self::Output>>where
Self::Output: 'a,
Transform an input stream into an output stream. Read more
Source§fn atransform<'a>(
&'a self,
input: BoxStream<'a, StringOrMessage>,
) -> BoxStream<'a, Result<Self::Output>>where
Self::Output: 'a,
fn atransform<'a>(
&'a self,
input: BoxStream<'a, StringOrMessage>,
) -> BoxStream<'a, Result<Self::Output>>where
Self::Output: 'a,
Async transform an input stream into an output stream.
Source§impl Clone for StrOutputParser
impl Clone for StrOutputParser
Source§fn clone(&self) -> StrOutputParser
fn clone(&self) -> StrOutputParser
Returns a duplicate of the value. Read more
1.0.0 · 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 StrOutputParser
impl Debug for StrOutputParser
Source§impl Default for StrOutputParser
impl Default for StrOutputParser
Source§fn default() -> StrOutputParser
fn default() -> StrOutputParser
Returns the “default value” for a type. Read more
Source§impl Serializable for StrOutputParser
impl Serializable for StrOutputParser
Source§fn get_lc_namespace() -> Vec<String>where
Self: Sized,
fn get_lc_namespace() -> Vec<String>where
Self: Sized,
Get the namespace of the LangChain object. Read more
Source§fn to_json(&self) -> Serialized
fn to_json(&self) -> Serialized
Serialize this object to JSON. Read more
Source§fn lc_secrets(&self) -> HashMap<String, String>
fn lc_secrets(&self) -> HashMap<String, String>
A map of constructor argument names to secret ids. Read more
Source§fn lc_attributes(&self) -> HashMap<String, Value>
fn lc_attributes(&self) -> HashMap<String, Value>
List of attribute names that should be included in the serialized kwargs. Read more
Source§fn lc_id() -> Vec<String>where
Self: Sized,
fn lc_id() -> Vec<String>where
Self: Sized,
Return a unique identifier for this class for serialization purposes. Read more
Source§fn lc_type_name(&self) -> &'static str
fn lc_type_name(&self) -> &'static str
Get the type name of this object.
Source§fn to_json_not_implemented(&self) -> Serialized
fn to_json_not_implemented(&self) -> Serialized
Serialize a “not implemented” object.
Auto Trait Implementations§
impl Freeze for StrOutputParser
impl RefUnwindSafe for StrOutputParser
impl Send for StrOutputParser
impl Sync for StrOutputParser
impl Unpin for StrOutputParser
impl UnwindSafe for StrOutputParser
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