Skip to content

Commit b21926f

Browse files
authored
docs(core): update StrOutputParser docstring (#34213)
1 parent f1ad0da commit b21926f

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

libs/core/langchain_core/output_parsers/string.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,33 @@
66

77

88
class StrOutputParser(BaseTransformOutputParser[str]):
9-
"""OutputParser that parses `LLMResult` into the top likely string."""
9+
"""Extract text content from model outputs as a string.
10+
11+
Converts model outputs (such as `AIMessage` or `AIMessageChunk` objects) into plain
12+
text strings. It's the simplest output parser and is useful when you need string
13+
responses for downstream processing, display, or storage.
14+
15+
Supports streaming, yielding text chunks as they're generated by the model.
16+
17+
Example:
18+
```python
19+
from langchain_core.output_parsers import StrOutputParser
20+
from langchain_openai import ChatOpenAI
21+
22+
model = ChatOpenAI(model="gpt-4o")
23+
parser = StrOutputParser()
24+
25+
# Get string output from a model
26+
message = model.invoke("Tell me a joke")
27+
result = parser.invoke(message)
28+
print(result) # plain string
29+
30+
# With streaming - use transform() to process a stream
31+
stream = model.stream("Tell me a story")
32+
for chunk in parser.transform(stream):
33+
print(chunk, end="", flush=True)
34+
```
35+
"""
1036

1137
@classmethod
1238
def is_lc_serializable(cls) -> bool:

libs/core/langchain_core/runnables/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ class Runnable(ABC, Generic[Input, Output]):
127127
Key Methods
128128
===========
129129
130-
- **`invoke`/`ainvoke`**: Transforms a single input into an output.
131-
- **`batch`/`abatch`**: Efficiently transforms multiple inputs into outputs.
132-
- **`stream`/`astream`**: Streams output from a single input as it's produced.
133-
- **`astream_log`**: Streams output and selected intermediate results from an
130+
- `invoke`/`ainvoke`: Transforms a single input into an output.
131+
- `batch`/`abatch`: Efficiently transforms multiple inputs into outputs.
132+
- `stream`/`astream`: Streams output from a single input as it's produced.
133+
- `astream_log`: Streams output and selected intermediate results from an
134134
input.
135135
136136
Built-in optimizations:

0 commit comments

Comments
 (0)