OutputParserException Class — langchain Architecture
Architecture documentation for the OutputParserException class in exceptions.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 0dd75536_e009_da4d_0090_3d46069fce40["OutputParserException"] 75598d2c_67b6_82ee_9927_fe755991e82f["LangChainException"] 0dd75536_e009_da4d_0090_3d46069fce40 -->|extends| 75598d2c_67b6_82ee_9927_fe755991e82f 445b6774_2020_8a8c_b7c7_f5804c232169["exceptions.py"] 0dd75536_e009_da4d_0090_3d46069fce40 -->|defined in| 445b6774_2020_8a8c_b7c7_f5804c232169 fce3a01a_3f42_aea4_cfc7_64f82c3763a2["__init__()"] 0dd75536_e009_da4d_0090_3d46069fce40 -->|method| fce3a01a_3f42_aea4_cfc7_64f82c3763a2
Relationship Graph
Source Code
libs/core/langchain_core/exceptions.py lines 15–65
class OutputParserException(ValueError, LangChainException): # noqa: N818
"""Exception that output parsers should raise to signify a parsing error.
This exists to differentiate parsing errors from other code or execution errors
that also may arise inside the output parser.
`OutputParserException` will be available to catch and handle in ways to fix the
parsing error, while other errors will be raised.
"""
def __init__(
self,
error: Any,
observation: str | None = None,
llm_output: str | None = None,
send_to_llm: bool = False, # noqa: FBT001,FBT002
):
"""Create an `OutputParserException`.
Args:
error: The error that's being re-raised or an error message.
observation: String explanation of error which can be passed to a model to
try and remediate the issue.
llm_output: String model output which is error-ing.
send_to_llm: Whether to send the observation and llm_output back to an Agent
after an `OutputParserException` has been raised.
This gives the underlying model driving the agent the context that the
previous output was improperly structured, in the hopes that it will
update the output to the correct format.
Raises:
ValueError: If `send_to_llm` is `True` but either observation or
`llm_output` are not provided.
"""
if isinstance(error, str):
error = create_message(
message=error, error_code=ErrorCode.OUTPUT_PARSING_FAILURE
)
super().__init__(error)
if send_to_llm and (observation is None or llm_output is None):
msg = (
"Arguments 'observation' & 'llm_output'"
" are required if 'send_to_llm' is True"
)
raise ValueError(msg)
self.observation = observation
self.llm_output = llm_output
self.send_to_llm = send_to_llm
Defined In
Extends
Source
Frequently Asked Questions
What is the OutputParserException class?
OutputParserException is a class in the langchain codebase, defined in libs/core/langchain_core/exceptions.py.
Where is OutputParserException defined?
OutputParserException is defined in libs/core/langchain_core/exceptions.py at line 15.
What does OutputParserException extend?
OutputParserException extends LangChainException.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free