StrOutputParser Class — langchain Architecture
Architecture documentation for the StrOutputParser class in string.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 27a4389f_3393_78db_e3ae_ef24f8d5ad97["StrOutputParser"] 2482376c_672b_4437_9420_27a3f2232d31["string.py"] 27a4389f_3393_78db_e3ae_ef24f8d5ad97 -->|defined in| 2482376c_672b_4437_9420_27a3f2232d31 235797ee_46ec_d7c6_addc_75a6aab1e50b["is_lc_serializable()"] 27a4389f_3393_78db_e3ae_ef24f8d5ad97 -->|method| 235797ee_46ec_d7c6_addc_75a6aab1e50b 46235aec_61b6_f1d5_c562_da97e8697efb["get_lc_namespace()"] 27a4389f_3393_78db_e3ae_ef24f8d5ad97 -->|method| 46235aec_61b6_f1d5_c562_da97e8697efb 149f2b07_9601_421a_c100_c201ec2a22ce["_type()"] 27a4389f_3393_78db_e3ae_ef24f8d5ad97 -->|method| 149f2b07_9601_421a_c100_c201ec2a22ce 228b9f01_3732_f917_e5ab_9c481a2f70e7["parse()"] 27a4389f_3393_78db_e3ae_ef24f8d5ad97 -->|method| 228b9f01_3732_f917_e5ab_9c481a2f70e7
Relationship Graph
Source Code
libs/core/langchain_core/output_parsers/string.py lines 8–63
class StrOutputParser(BaseTransformOutputParser[str]):
"""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:
"""`StrOutputParser` is serializable.
Returns:
`True`
"""
return True
@classmethod
def get_lc_namespace(cls) -> list[str]:
"""Get the namespace of the LangChain object.
Returns:
`["langchain", "schema", "output_parser"]`
"""
return ["langchain", "schema", "output_parser"]
@property
def _type(self) -> str:
"""Return the output parser type for serialization."""
return "default"
@override
def parse(self, text: str) -> str:
"""Returns the input text with no changes."""
return text
Source
Frequently Asked Questions
What is the StrOutputParser class?
StrOutputParser is a class in the langchain codebase, defined in libs/core/langchain_core/output_parsers/string.py.
Where is StrOutputParser defined?
StrOutputParser is defined in libs/core/langchain_core/output_parsers/string.py at line 8.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free