Skip to content

Conversation

@Chase-Xuu
Copy link

Summary

When a conditional router returns END ('__end__') but path_map does not include an explicit END mapping, the code raises KeyError('__end__').

Fix

This PR treats END as a special case in _branch.py's _finish method - it now passes through directly without requiring a path_map entry, matching user expectations.

The Change

# Before
destinations = [r if isinstance(r, Send) else self.ends[r] for r in result]

# After  
destinations = [r if isinstance(r, Send) else (r if r == END else self.ends[r]) for r in result]

Fixes #6770

When a conditional router returns END ('__end__') but path_map does not
include an explicit END mapping, the code would raise KeyError('__end__').

This fix treats END as a special case that passes through directly
without requiring a path_map entry, matching user expectations.

Fixes langchain-ai#6770
@Chase-Xuu Chase-Xuu force-pushed the fix/issue-6770-end-keyerror branch from f6b5add to f203fcd Compare February 9, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeyError('__end__') at runtime when conditional router returns '__end__' but path_map does not include END mapping

1 participant