langchain-ai/langchain · error · ValueError
Batch size must be a positive integer, got {size}.
Error message
Batch size must be a positive integer, got {size}. What it means
Error "Batch size must be a positive integer, got {size}." thrown in langchain-ai/langchain.
Source
Thrown at libs/core/langchain_core/utils/iter.py:223
def batch_iterate(size: int | None, iterable: Iterable[T]) -> Iterator[list[T]]:
"""Utility batching function.
Args:
size: The size of the batch.
If `None`, returns a single batch.
iterable: The iterable to batch.
Yields:
The batches of the iterable.
Raises:
ValueError: If `size` is not `None` and is not a positive integer.
"""
if size is not None and size <= 0:
msg = f"Batch size must be a positive integer, got {size}."
raise ValueError(msg)
it = iter(iterable)
while True:
chunk = list(islice(it, size))
if not chunk:
return
yield chunk
View on GitHub (pinned to e32fa9a52e)
Solutions
- Pass a batch size that is a positive integer (>= 1).
- If the size comes from configuration, validate it before calling batching.
Example fix
for chunk in batch_iterate(size=max(1, batch_size), iterable=items): ...
When it happens
Trigger: Raised when a batch() helper is called with a batch size that is not a positive integer (zero or negative).
Common situations: See trigger scenarios.
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/aa67403bf336f8f8.
Report an issue: GitHub.