跳转到内容

异常

langchain_core.exceptions.OutputParserException

基类: ValueError, LangChainException

输出解析器在遇到解析错误时应引发的异常。

此异常的存在是为了区分解析错误与输出解析器内部可能出现的其他代码或执行错误。

OutputParserException 可以被捕获和处理,以修复解析错误,而其他错误则会被直接抛出。

方法 描述
__init__

创建一个 OutputParserException

__init__

__init__(
    error: Any,
    observation: str | None = None,
    llm_output: str | None = None,
    send_to_llm: bool = False,
)

创建一个 OutputParserException

参数 描述
error

被重新引发的错误或一条错误消息。

类型: Any

observation

对错误的字符串解释,可以传递给模型以尝试修复问题。

类型: str | None 默认值: None

llm_output

导致错误的模型输出字符串。

类型: str | None 默认值: None

send_to_llm

在引发 OutputParserException 后,是否将 observation 和 llm_output 发送回 Agent。

这为驱动 Agent 的底层模型提供了上下文,告知其先前的输出结构不正确,希望它能将输出更新为正确的格式。

类型: bool 默认值: False

引发 描述
ValueError

如果 send_to_llmTrue,但 observation 或 llm_output 未提供。

© . This site is unofficial and not affiliated with LangChain, Inc.