跳到内容

INVALID_GRAPH_NODE_RETURN_VALUE

LangGraph StateGraph 接收到来自节点的非字典返回类型。这是一个例子

class State(TypedDict):
    some_key: str

def bad_node(state: State):
    # Should return an dict with a value for "some_key", not a list
    return ["whoops"]

builder = StateGraph(State)
builder.add_node(bad_node)
...

graph = builder.compile()

调用上面的图将导致如下错误

graph.invoke({ "some_key": "someval" });
InvalidUpdateError: Expected dict, got ['whoops']
For troubleshooting, visit: https://python.langchain.ac.cn/docs/troubleshooting/errors/INVALID_GRAPH_NODE_RETURN_VALUE

图中的节点必须返回一个字典,其中包含在您的状态中定义的一个或多个键。

故障排除

以下方法可能有助于解决此错误

  • 如果您的节点中有复杂的逻辑,请确保所有代码路径都为您的定义状态返回适当的字典。

评论