{"record":{"id":"4fe56aab9b4a821b","repo":"langchain-ai/langchain","slug":"run-name-must-be-a-list-of-the-same-length-as-prom","errorCode":null,"errorMessage":"run_name must be a list of the same length as prompts","messagePattern":"run_name must be a list of the same length as prompts","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/language_models/llms.py","lineNumber":954,"sourceCode":"            # We've received a list of callbacks args to apply to each input\n            if len(callbacks) != len(prompts):\n                msg = \"callbacks must be the same length as prompts\"\n                raise ValueError(msg)\n            if tags is not None and not (\n                isinstance(tags, list) and len(tags) == len(prompts)\n            ):\n                msg = \"tags must be a list of the same length as prompts\"\n                raise ValueError(msg)\n            if metadata is not None and not (\n                isinstance(metadata, list) and len(metadata) == len(prompts)\n            ):\n                msg = \"metadata must be a list of the same length as prompts\"\n                raise ValueError(msg)\n            if run_name is not None and not (\n                isinstance(run_name, list) and len(run_name) == len(prompts)\n            ):\n                msg = \"run_name must be a list of the same length as prompts\"\n                raise ValueError(msg)\n            tags_list = cast(\"list[list[str] | None]\", tags or ([None] * len(prompts)))\n            metadata_list = cast(\n                \"list[builtins.dict[str, Any] | None]\",\n                metadata or ([{}] * len(prompts)),\n            )\n            run_name_list = run_name or cast(\n                \"list[str | None]\", ([None] * len(prompts))\n            )\n            params = self._dict_for_compat()\n            params[\"stop\"] = stop\n            callback_managers = [\n                CallbackManager.configure(\n                    callback,\n                    self.callbacks,\n                    self.verbose,\n                    tag,\n                    self.tags,\n                    meta,","sourceCodeStart":936,"sourceCodeEnd":972,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/language_models/llms.py#L936-L972","documentation":"Raised by BaseLLM.generate when run_name is supplied with per-prompt callbacks but is not a list whose length equals the number of prompts. Each prompt needs its own run name entry when per-prompt callback configs are used.","triggerScenarios":"llm.generate(prompts, callbacks=[[cb], [cb]], run_name='my-run') with more than one prompt; or run_name=['a', 'b'] for three prompts. Triggered only when callbacks is a per-prompt list.","commonSituations":"Naming LangSmith runs for batched requests and passing a single string run_name out of habit from invoke(); partial lists after editing the prompt batch.","solutions":["Provide one run name per prompt: run_name=['run-1', 'run-2', ...] matching len(prompts)","Or pass run_name=None and let LangChain auto-generate run names","Or use shared callbacks instead of per-prompt callbacks if a single run_name is desired"],"exampleFix":"# before\nllm.generate(prompts, callbacks=per_prompt_cbs, run_name='batch-run')\n# after\nllm.generate(prompts, callbacks=per_prompt_cbs, run_name=[f'batch-run-{i}' for i in range(len(prompts))])","handlingStrategy":"validation","validationCode":"n = len(prompts)\nif run_name is not None:\n    assert isinstance(run_name, list) and len(run_name) == n, f'run_name must be a list of {n} strings'","typeGuard":"def valid_batch_run_name(rn: object, n: int) -> bool:\n    return rn is None or (isinstance(rn, list) and len(rn) == n and all(isinstance(x, str) for x in rn))","tryCatchPattern":"try:\n    llm.generate(prompts, callbacks=cbs, run_name=run_name)\nexcept ValueError as e:\n    if 'run_name must be a list' in str(e) and isinstance(run_name, str):\n        llm.generate(prompts, callbacks=cbs, run_name=[run_name] * len(prompts))\n    else:\n        raise","preventionTips":["Generate run names with a comprehension tied to prompts: [f'{base}-{i}' for i in range(len(prompts))]","A bare string run_name is only valid when callbacks is not a per-prompt list"],"tags":["llm","batch","run-name","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}