[PR #6089] bug fix: In Router class using str instead of Literal[*options] due t… #4826

Closed
opened 2026-02-20 17:50:48 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/6089

State: closed
Merged: No


Description:
This PR fixes the supervisor routing bug reported in #6088

Previously, make_supervisor_node used Literal[*options] in the Router schema to define valid routing options. This approach caused syntax limitations and broke compatibility with some Python versions and typing contexts.

This PR replaces the Literal unpacking with a simple str type and adds runtime validation to ensure the supervisor only routes to valid worker names or FINISH. If the LLM outputs an invalid option, a clear ValueError is raised.

This change keeps the API stable and backwards compatible while removing reliance on unsupported typing syntax.

Errors Solved:

Error - 1.  next: Literal[*options]
                    ^
     SyntaxError: invalid syntax

If we fix the above error with something like
next: Literal[tuple(options)]

We get the below error:

Error - 2. ValueError: Found edge ending at unknown node ('search', 'web_scraper')

The fix uses Literal[*options] to properly expand into a union of worker names (e.g. Literal["FINISH", "search", "web_scraper"]). This ensures that supervisor routing works as intended.

Issue:
Closes #6088

Dependencies:
No new dependencies.

Twitter handle (optional): @


Tests and Docs

  • The whole notebook runs fine with the change performed; no new unit tests/ test cases are added.

Checklist

  • Linting: make format, make lint
  • Tests passing: make test
  • Docs updated with example

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/6089 **State:** closed **Merged:** No --- **Description:** This PR fixes the supervisor routing bug reported in [#6088](https://github.com/langchain-ai/langgraph/issues/6088) Previously, make_supervisor_node used Literal[*options] in the Router schema to define valid routing options. This approach caused syntax limitations and broke compatibility with some Python versions and typing contexts. This PR replaces the Literal unpacking with a simple str type and adds runtime validation to ensure the supervisor only routes to valid worker names or FINISH. If the LLM outputs an invalid option, a clear ValueError is raised. This change keeps the API stable and backwards compatible while removing reliance on unsupported typing syntax. Errors Solved: ``` Error - 1. next: Literal[*options] ^ SyntaxError: invalid syntax ``` If we fix the above error with something like `next: Literal[tuple(options)]` We get the below error: ``` Error - 2. ValueError: Found edge ending at unknown node ('search', 'web_scraper') ``` The fix uses `Literal[*options]` to properly expand into a union of worker names (e.g. `Literal["FINISH", "search", "web_scraper"]`). This ensures that supervisor routing works as intended. **Issue:** Closes [#6088](https://github.com/langchain-ai/langgraph/issues/6088) **Dependencies:** No new dependencies. **Twitter handle (optional):** @<your-handle-here> --- ### **Tests and Docs** * The whole notebook runs fine with the change performed; no new unit tests/ test cases are added. --- ### **Checklist** * [x] Linting: `make format`, `make lint` * [x] Tests passing: `make test` * [x] Docs updated with example ---
yindo added the pull-request label 2026-02-20 17:50:48 -05:00
yindo closed this issue 2026-02-20 17:50:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#4826