{"record":{"id":"28cc72b57df10256","repo":"langchain-ai/langchain","slug":"config-must-be-a-list-of-the-same-length-as-inputs","errorCode":null,"errorMessage":"config must be a list of the same length as inputs, but got {len(config)} configs for {length} inputs","messagePattern":"config must be a list of the same length as inputs, but got (.+?) configs for (.+?) inputs","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/runnables/config.py","lineNumber":337,"sourceCode":"        config: The config or list of configs.\n        length: The length of the list.\n\n    Returns:\n        The list of configs.\n\n    Raises:\n        ValueError: If the length of the list is not equal to the length of the inputs.\n\n    \"\"\"\n    if length < 0:\n        msg = f\"length must be >= 0, but got {length}\"\n        raise ValueError(msg)\n    if isinstance(config, Sequence) and len(config) != length:\n        msg = (\n            f\"config must be a list of the same length as inputs, \"\n            f\"but got {len(config)} configs for {length} inputs\"\n        )\n        raise ValueError(msg)\n\n    if isinstance(config, Sequence):\n        return list(map(ensure_config, config))\n    if length > 1 and isinstance(config, dict) and config.get(\"run_id\") is not None:\n        warnings.warn(\n            \"Provided run_id be used only for the first element of the batch.\",\n            category=RuntimeWarning,\n            stacklevel=3,\n        )\n        subsequent = cast(\n            \"RunnableConfig\", {k: v for k, v in config.items() if k != \"run_id\"}\n        )\n        return [\n            ensure_config(subsequent) if i else ensure_config(config)\n            for i in range(length)\n        ]\n    return [ensure_config(config) for i in range(length)]\n","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/runnables/config.py#L319-L355","documentation":"When a `config` for a batch operation is given as a sequence, `get_config_list` requires `len(config) == length`, where `length` is the number of inputs being processed. A mismatch means some inputs would have no config (or configs would be silently dropped), so `ValueError` is raised reporting both counts.","triggerScenarios":"Calling `.batch(inputs, config=[cfg1, cfg2])` with 3 inputs, or `.batch([x], config=[cfg1, cfg2])`; also custom code that zips inputs with a differently-sized config list, or slices inputs (`inputs[1:]`) while passing the full config list.","commonSituations":"Reusing a config list built for a previous batch size; parallel workers processing shards of inputs with the unsharded config list; passing `config=` per-item dicts when a single shared `RunnableConfig` dict was intended (and vice versa when a list was intended).","solutions":["Make the config list match the inputs one-to-one: build it with a list comprehension over the inputs.","If all inputs share one config, pass a single dict instead of a list: `.batch(inputs, config=shared_cfg)`.","When sharding inputs, shard the configs identically: `.batch(inputs[i:j], config=configs[i:j])`."],"exampleFix":"# before\nresults = chain.batch(inputs, config=[cfg1, cfg2])  # len(inputs) == 3\n\n# after\nresults = chain.batch(inputs, config=[make_cfg(i) for i in range(len(inputs))])","handlingStrategy":"validation","validationCode":"if isinstance(config, list):\n    assert len(config) == len(inputs), f\"{len(config)} configs vs {len(inputs)} inputs\"\nchain.batch(inputs, config=config)","typeGuard":null,"tryCatchPattern":"try:\n    chain.batch(inputs, config=configs)\nexcept ValueError as e:\n    if \"same length as inputs\" in str(e):\n        configs = [configs[i % len(configs)] for i in range(len(inputs))]\n        chain.batch(inputs, config=configs)\n    else:\n        raise","preventionTips":["Build config lists with a comprehension over inputs so lengths always match.","Pass a single shared dict when all items use the same config.","Shard configs together with inputs when parallelizing."],"tags":["config","batch","value-error","langchain-core"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}