OUTPUT_PARSING_FAILURE
输出解析器 无法按预期处理模型输出。
¥An output parser was unable to handle model output as expected.
为了说明这一点,假设你有一个输出解析器,它要求聊天模型输出由 Markdown 代码标签(三个反引号)包围的 JSON。这是一个良好输入的示例:
¥To illustrate this, let's say you have an output parser that expects a chat model to output JSON surrounded by a markdown code tag (triple backticks). Here would be an example of good input:
AIMessage {
content: "```\n{\"foo\": \"bar\"}\n```"
}
在内部,我们的输出解析器可能会尝试去除 Markdown 栅栏和换行符,然后运行 JSON.parse()
。
¥Internally, our output parser might try to strip out the markdown fence and newlines and then run JSON.parse()
.
如果聊天模型生成的输出包含如下格式错误的 JSON:
¥If instead the chat model generated an output with malformed JSON like this:
AIMessage {
content: "```\n{\"foo\":\n```"
}
当我们的输出解析器尝试解析此字符串时,JSON.parse()
调用将失败。
¥When our output parser attempts to parse this, the JSON.parse()
call will fail.
请注意,某些预构建结构(例如 旧版 LangChain 代理 和链)可能在内部使用输出解析器,因此即使你没有明显实例化和使用输出解析器,也可能会看到此错误。
¥Note that some prebuilt constructs like legacy LangChain agents and chains may use output parsers internally, so you may see this error even if you're not visibly instantiating and using an output parser.
故障排除
¥Troubleshooting
以下内容可能有助于解决此错误:
¥The following may help resolve this error:
如果可能,请考虑在没有输出解析器的情况下使用 工具调用或其他结构化输出技术 来可靠地输出可解析的值。
¥Consider using tool calling or other structured output techniques if possible without an output parser to reliably output parseable values.
在你的提示中添加更精确的格式化指令。在上面的示例中,将
"You must always return valid JSON fenced by a markdown code block. Do not return any additional text."
添加到输入中可能有助于引导模型返回预期的格式。¥Add more precise formatting instructions to your prompt. In the above example, adding
"You must always return valid JSON fenced by a markdown code block. Do not return any additional text."
to your input may help steer the model to returning the expected format.如果你使用的模型规模较小或功能较弱,请尝试使用功能更强大的模型。
¥If you are using a smaller or less capable model, try using a more capable one.
添加 LLM 驱动的重试。
¥Add LLM-powered retries.