langchain-ai/langchain · error · ValueError

No generations found in stream.

Error message

No generations found in stream.

What it means

`ValueError` from `generate_from_stream`: the first `next(stream, None)` returned a falsy value, meaning the generation stream was empty. The helper is used when a chat model is asked to build a `ChatResult` from a stream of `ChatGenerationChunk`s and at least one chunk is required.

Source

Thrown at libs/core/langchain_core/language_models/chat_models.py:224

def generate_from_stream(stream: Iterator[ChatGenerationChunk]) -> ChatResult:
    """Generate from a stream.

    Args:
        stream: Iterator of `ChatGenerationChunk`.

    Raises:
        ValueError: If no generations are found in the stream.

    Returns:
        Chat result.

    """
    generation = next(stream, None)
    if generation:
        generation += list(stream)
    if generation is None:
        msg = "No generations found in stream."
        raise ValueError(msg)
    return ChatResult(
        generations=[
            ChatGeneration(
                message=message_chunk_to_message(generation.message),
                generation_info=generation.generation_info,
            )
        ]
    )


async def agenerate_from_stream(
    stream: AsyncIterator[ChatGenerationChunk],
) -> ChatResult:
    """Async generate from a stream.

    Args:
        stream: AsyncIterator of `ChatGenerationChunk`.

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Verify the provider actually returns chunks for the request (test the raw API call with `curl` or the provider SDK directly).
  2. Fix custom `_stream` overrides to always yield at least one `ChatGenerationChunk` (see `fake_chat_models` for the expected pattern).
  3. If the provider can legitimately return empty streams, catch `ValueError` and return an empty `AIMessage` instead.
  4. Check for proxy/gateway interference that drops `text/event-stream` payloads.

Example fix

# before
async def _stream(self, messages, **kw):
    if not messages:
        return
    yield ...  # early return leaves stream empty

# after
async def _stream(self, messages, **kw):
    yield ChatGenerationChunk(message=AIMessageChunk(content=self._call(messages)))
Defensive patterns

Strategy: validation

Validate before calling

first = next(stream, None)
if first is None:
    raise ValueError("provider returned an empty stream")
generation = first + list(stream)

Try / catch

try:
    result = generate_from_stream(stream)
except ValueError as e:
    if "No generations found" in str(e):
        # retry once or degrade to non-streaming call
        result = model.generate([messages])
    else:
        raise

Prevention

When it happens

Trigger: Calling a model with `stream=True` (or the `_generate_with_cache` fallback path calling `generate_from_stream`) when the underlying stream iterator yields no chunks, or yields only a chunk that is falsy (e.g. an empty `ChatGenerationChunk`).

Common situations: Custom `_stream` implementations that return without yielding; providers returning an empty response body (200 with no chunks); network proxies stripping SSE events; `stream_mode` misconfiguration producing zero chunks.

Related errors


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/0f1841ad0fe0440a. Report an issue: GitHub.