Skip to main content
一个 LangGraph StateGraph 从一个节点接收到了非字典返回类型。以下是一个示例:
class State(TypedDict):
    some_key: str

def bad_node(state: State):
    # Should return a 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.com/docs/troubleshooting/errors/INVALID_GRAPH_NODE_RETURN_VALUE
您的图中的节点必须返回一个包含您状态中定义的一个或多个键的字典。

故障排除

以下可能有助于解决此错误:
  • 如果您的节点中包含复杂逻辑,请确保所有代码路径都返回您定义状态的一个适当字典。