Skip to content

The agent engineering platform.

docs(core): update `StrOutputParser` docstring (#34213)

Mason Daughertyb21926fe6c50
diff --git a/libs/core/langchain_core/output_parsers/string.py b/libs/core/langchain_core/output_parsers/string.py
index 4b189e1c46..0d8f3bb6ed 100644
--- a/libs/core/langchain_core/output_parsers/string.py
+++ b/libs/core/langchain_core/output_parsers/string.py
@@ -6,7 +6,33 @@ from langchain_core.output_parsers.transform import BaseTransformOutputParser
class StrOutputParser(BaseTransformOutputParser[str]):
- """OutputParser that parses `LLMResult` into the top likely string."""
+ """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:
+ ```python
+ from langchain_core.output_parsers import StrOutputParser
+ from langchain_openai import ChatOpenAI
+
+ model = ChatOpenAI(model="gpt-4o")
+ parser = StrOutputParser()
+
+ # Get string output from a model
+ message = model.invoke("Tell me a joke")
+ result = parser.invoke(message)
+ print(result) # plain string
+
+ # With streaming - use transform() to process a stream
+ stream = model.stream("Tell me a story")
+ for chunk in parser.transform(stream):
+ print(chunk, end="", flush=True)
+ ```
+ """
@classmethod
def is_lc_serializable(cls) -> bool:
diff --git a/libs/core/langchain_core/runnables/base.py b/libs/core/langchain_core/runnables/base.py
index 9910eb6fbd..d9ee99555e 100644
--- a/libs/core/langchain_core/runnables/base.py
+++ b/libs/core/langchain_core/runnables/base.py
@@ -127,10 +127,10 @@ class Runnable(ABC, Generic[Input, Output]):
Key Methods
===========
- - **`invoke`/`ainvoke`**: Transforms a single input into an output.
- - **`batch`/`abatch`**: Efficiently transforms multiple inputs into outputs.
- - **`stream`/`astream`**: Streams output from a single input as it's produced.
- - **`astream_log`**: Streams output and selected intermediate results from an
+ - `invoke`/`ainvoke`: Transforms a single input into an output.
+ - `batch`/`abatch`: Efficiently transforms multiple inputs into outputs.
+ - `stream`/`astream`: Streams output from a single input as it's produced.
+ - `astream_log`: Streams output and selected intermediate results from an
input.
Built-in optimizations: