Source code for langchain_core.exceptions
"""为LangChain自定义 **异常** 。"""
from typing import Any, Optional
[docs]class LangChainException(Exception):
"""通用的LangChain异常。"""
[docs]class TracerException(LangChainException):
"""用于跟踪器模块中异常的基类。"""
[docs]class OutputParserException(ValueError, LangChainException):
"""输出解析器应该引发的异常,表示解析错误。
这是为了区分解析错误和其他可能在输出解析器内部出现的代码或执行错误。OutputParserExceptions将可用于捕获和处理以修复解析错误,而其他错误将被引发。
参数:
error: 被重新引发的错误或错误消息。
observation: 错误的字符串解释,可以传递给模型以尝试纠正问题。
llm_output: 出错的字符串模型输出。
send_to_llm: 是否在引发OutputParserException后将观察和llm_output发送回代理。这为驱动代理的底层模型提供了上下文,说明先前的输出结构不正确,希望它将输出更新为正确的格式。
"""
def __init__(
self,
error: Any,
observation: Optional[str] = None,
llm_output: Optional[str] = None,
send_to_llm: bool = False,
):
super(OutputParserException, self).__init__(error)
if send_to_llm:
if observation is None or llm_output is None:
raise ValueError(
"Arguments 'observation' & 'llm_output'"
" are required if 'send_to_llm' is True"
)
self.observation = observation
self.llm_output = llm_output
self.send_to_llm = send_to_llm