langchain-ai/langgraph · error · ValueError
Branch did not return a valid destination
Error message
Branch did not return a valid destination
What it means
Raised by RunnableBranch._finish when the branch function returns a destination that is None or START. Branch results must be node names, Send objects, or END; None and START are invalid routing targets.
Solutions
- Return END (not START) to terminate the graph from a branch
- Return None-safe logic: make sure every code path returns a valid node name or Send
- Map results through the `ends` dict passed to add_conditional_edges so raw results are translated
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at libs/langgraph/langgraph/graph/_branch.py:208 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of langchain-ai/langgraph@38031739e5 (2026-08-26).
Data as JSON: /api/errors/196414f3d616528d.
Report an issue: GitHub.
Appendix: source
Thrown at libs/langgraph/langgraph/graph/_branch.py:208
return self._finish(writer, input, result, config)
def _finish(
self,
writer: _Writer,
input: Any,
result: Any,
config: RunnableConfig,
) -> Runnable | Any:
if not isinstance(result, (list, tuple)):
result = [result]
if self.ends:
destinations: Sequence[Send | str] = [
r if isinstance(r, Send) else self.ends[r] for r in result
]
else:
destinations = cast(Sequence[Send | str], result)
if any(dest is None or dest == START for dest in destinations):
raise ValueError("Branch did not return a valid destination")
if any(p.node == END for p in destinations if isinstance(p, Send)):
raise InvalidUpdateError("Cannot send a packet to the END node")
entries = writer(destinations, False)
if not entries:
return input
else:
need_passthrough = False
for e in entries:
if isinstance(e, ChannelWriteEntry):
if e.value is PASSTHROUGH:
need_passthrough = True
break
if need_passthrough:
return ChannelWrite(entries)
else:
ChannelWrite.do_write(config, entries)
return input
View on GitHub (pinned to 38031739e5)