StrOutputParser

Struct StrOutputParser 

Source
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

Source

pub fn new() -> Self

Create a new StrOutputParser.

Source

pub fn is_lc_serializable() -> bool

Returns true as this class is serializable.

Source

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

Source§

fn parse(&self, text: &str) -> Result<String>

Returns the input text with no changes.

Source§

fn parser_type(&self) -> &str

Return the output parser type for serialization.

Source§

type Output = String

The output type of this parser.
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,

Async parse a single string model output into some structure. Read more
Source§

fn parse_result( &self, result: &[Generation], _partial: bool, ) -> Result<Self::Output>

Parse a list of candidate model Generation objects into a specific format. Read more
Source§

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>

Parse the output of an LLM call with the input prompt for context. Read more
Source§

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>

Invoke the parser on input. Read more
Source§

fn ainvoke<'life0, 'async_trait>( &'life0 self, input: BaseMessage, config: Option<RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Async invoke the parser on input.
Source§

impl BaseTransformOutputParser for StrOutputParser

Source§

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,

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,

Async transform an input stream into an output stream.
Source§

impl Clone for StrOutputParser

Source§

fn clone(&self) -> StrOutputParser

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StrOutputParser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StrOutputParser

Source§

fn default() -> StrOutputParser

Returns the “default value” for a type. Read more
Source§

impl Serializable for StrOutputParser

Source§

fn is_lc_serializable() -> bool
where Self: Sized,

Is this class serializable? Read more
Source§

fn get_lc_namespace() -> Vec<String>
where Self: Sized,

Get the namespace of the LangChain object. Read more
Source§

fn to_json(&self) -> Serialized
where Self: Sized + Serialize,

Serialize this object to JSON. Read more
Source§

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>

List of attribute names that should be included in the serialized kwargs. Read more
Source§

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

Get the type name of this object.
Source§

fn to_json_not_implemented(&self) -> Serialized

Serialize a “not implemented” object.
Source§

impl Serialize for StrOutputParser

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more