langchain-ai/langgraph · error · NotImplementedError

Generators are not supported in the Functional API.

Error message

Generators are not supported in the Functional API.

What it means

Raised by entrypoint's __call__ when the wrapped function is a generator or async generator function. The Functional API entrypoint contract requires a plain (sync or async) function returning a value; yielding is not supported.

Solutions

  1. Rewrite the generator as a plain function that returns the final value
  2. Use StreamWriter (available via get_stream_writer()) to emit intermediate values instead of yielding
  3. Use a task/subgraph API if streaming yields are essential
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at libs/langgraph/langgraph/func/__init__.py:527 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/981953c618e7187e. Report an issue: GitHub.

Appendix: source

Thrown at libs/langgraph/langgraph/func/__init__.py:527

        """Value to return. A value will always be returned even if it is `None`."""
        save: S
        """The value for the state for the next checkpoint.

        A value will always be saved even if it is `None`.
        """

    def __call__(self, func: Callable[..., Any]) -> Pregel:
        """Convert a function into a Pregel graph.

        Args:
            func: The function to convert. Support both sync and async functions.

        Returns:
            A Pregel graph.
        """
        # wrap generators in a function that writes to StreamWriter
        if inspect.isgeneratorfunction(func) or inspect.isasyncgenfunction(func):
            raise NotImplementedError(
                "Generators are not supported in the Functional API."
            )

        bound = get_runnable_for_entrypoint(func)
        stream_mode: StreamMode = "updates"

        # get input and output types
        sig = inspect.signature(func)
        first_parameter_name = next(iter(sig.parameters.keys()), None)
        if not first_parameter_name:
            raise ValueError("Entrypoint function must have at least one parameter")
        input_type = (
            sig.parameters[first_parameter_name].annotation
            if sig.parameters[first_parameter_name].annotation
            is not inspect.Signature.empty
            else Any
        )

View on GitHub (pinned to 38031739e5)