langchain-ai/langchain · error · ValueError
Number of manually provided run_id's does not match batch le
Error message
Number of manually provided run_id's does not match batch length. {len(run_id)} != {len(prompts)} What it means
Raised by BaseLLM._get_run_ids_list when run_id is passed as a list to generate but its length differs from the number of prompts. Manually supplied run IDs must map one-to-one onto the batch so each LLM run gets a deterministic UUID.
Source
Thrown at libs/core/langchain_core/language_models/llms.py:1088
else:
llm_output = {}
run_info = None
generations = [existing_prompts[i] for i in range(len(prompts))]
return LLMResult(generations=generations, llm_output=llm_output, run=run_info)
@staticmethod
def _get_run_ids_list(
run_id: uuid.UUID | list[uuid.UUID | None] | None, prompts: list[str]
) -> list[uuid.UUID | None]:
if run_id is None:
return [None] * len(prompts)
if isinstance(run_id, list):
if len(run_id) != len(prompts):
msg = (
"Number of manually provided run_id's does not match batch length."
f" {len(run_id)} != {len(prompts)}"
)
raise ValueError(msg)
return run_id
return [run_id] + [None] * (len(prompts) - 1)
async def _agenerate_helper(
self,
prompts: list[str],
stop: list[str] | None,
run_managers: list[AsyncCallbackManagerForLLMRun],
*,
new_arg_supported: bool,
**kwargs: Any,
) -> LLMResult:
try:
output = (
await self._agenerate(
prompts,
stop=stop,
run_manager=run_managers[0] if run_managers else None,View on GitHub (pinned to e32fa9a52e)
Solutions
- Build one UUID per prompt: run_id=[uuid.uuid4() for _ in prompts]
- Or pass a single uuid.UUID to apply it to the first prompt only
- Or pass run_id=None to let LangChain generate IDs
Example fix
# before llm.generate(prompts, run_id=[uuid.uuid4()]) # after llm.generate(prompts, run_id=[uuid.uuid4() for _ in prompts])
Defensive patterns
Strategy: validation
Validate before calling
if isinstance(run_id, list):
assert len(run_id) == len(prompts), f'{len(run_id)} run_ids for {len(prompts)} prompts' Type guard
def valid_run_ids(run_id: object, n: int) -> bool:
import uuid
if run_id is None or isinstance(run_id, uuid.UUID):
return True
return isinstance(run_id, list) and len(run_id) == n and all(i is None or isinstance(i, uuid.UUID) for i in run_id) Try / catch
try:
llm.generate(prompts, run_id=run_ids)
except ValueError as e:
if 'run_id' in str(e) and len(run_ids) < len(prompts):
run_ids = run_ids + [uuid.uuid4() for _ in range(len(prompts) - len(run_ids))]
llm.generate(prompts, run_id=run_ids)
else:
raise Prevention
- Always derive the run_id list from the prompts: [uuid.uuid4() for _ in prompts]
- Persist one UUID per prompt when replaying batches for LangSmith correlation
When it happens
Trigger: llm.generate([p1, p2, p3], run_id=[uuid1, uuid2]) — 2 IDs for 3 prompts. A single UUID (not in a list) is accepted and applied to the first prompt only; only a mismatched list raises.
Common situations: Replaying or resuming batched requests with fixed run IDs (e.g. for LangSmith trace correlation or idempotent caching) and forgetting to regenerate the ID list after changing batch size.
Related errors
- tags must be a list of the same length as prompts
- metadata must be a list of the same length as prompts
- run_name must be a list of the same length as prompts
- Argument 'prompts' is expected to be of type list[str], rece
- invalid IP address
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/410a66ea320fb6e7.
Report an issue: GitHub.