{"record":{"id":"d7be18a2094bd2e8","repo":"langchain-ai/langchain","slug":"if-exception-key-is-specified-then-inputs-must-b","errorCode":null,"errorMessage":"If 'exception_key' is specified then inputs must be dictionaries.However found a type of {type(inputs[0])} for input","messagePattern":"If 'exception_key' is specified then inputs must be dictionaries\\.However found a type of (.+?) for input","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/runnables/fallbacks.py","lineNumber":280,"sourceCode":"        raise first_error\n\n    @override\n    def batch(\n        self,\n        inputs: list[Input],\n        config: RunnableConfig | list[RunnableConfig] | None = None,\n        *,\n        return_exceptions: bool = False,\n        **kwargs: Any | None,\n    ) -> list[Output]:\n        if self.exception_key is not None and not all(\n            isinstance(input_, dict) for input_ in inputs\n        ):\n            msg = (\n                \"If 'exception_key' is specified then inputs must be dictionaries.\"\n                f\"However found a type of {type(inputs[0])} for input\"\n            )\n            raise ValueError(msg)\n\n        if not inputs:\n            return []\n\n        # setup callbacks\n        configs = get_config_list(config, len(inputs))\n        callback_managers = [\n            CallbackManager.configure(\n                inheritable_callbacks=config.get(\"callbacks\"),\n                local_callbacks=None,\n                verbose=False,\n                inheritable_tags=config.get(\"tags\"),\n                local_tags=None,\n                inheritable_metadata=config.get(\"metadata\"),\n                local_metadata=None,\n            )\n            for config in configs\n        ]","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/runnables/fallbacks.py#L262-L298","documentation":"`RunnableWithFallbacks.batch` validates every element of `inputs` is a `dict` when `exception_key` is set, because each failing run's error is written into its corresponding input dict for the fallbacks to see. If any element is not a dict, `ValueError` is raised before batching starts; the message reports the type of the first element.","triggerScenarios":"`fb.batch([\"a\", \"b\"])` or `fb.batch([dict_input, string_input])` on a runnable created with `.with_fallbacks(..., exception_key=\"errors\")`; mixing formats when batching heterogeneous requests; a producer that sometimes yields strings instead of payload dicts.","commonSituations":"Batching prompts as strings with a fallback-wrapped parser; a queue consumer where some messages are already dicts and others are raw text; reusing the `exception_key` feature with legacy string inputs after upgrading the pipeline.","solutions":["Normalize every input to a dict before batching: `[x if isinstance(x, dict) else {\"text\": x} for x in inputs]`.","Remove `exception_key` from `with_fallbacks` if per-item error capture is unnecessary.","Add a validation pass that rejects/logs non-dict entries at ingestion time."],"exampleFix":"# before\nouts = fb.batch(prompts)  # prompts: list[str], fb has exception_key\n\n# after\nouts = fb.batch([{\"text\": p} for p in prompts])","handlingStrategy":"validation","validationCode":"inputs = [x if isinstance(x, dict) else {\"text\": x} for x in inputs]\nfb.batch(inputs)","typeGuard":"from typing import TypeGuard\n\ndef all_dicts(xs: list[object]) -> TypeGuard[list[dict]]:\n    return all(isinstance(x, dict) for x in xs)","tryCatchPattern":null,"preventionTips":["Normalize batch items to dicts at the producer boundary.","Reject or log non-dict entries at ingestion instead of at batch time.","Avoid exception_key unless every batch item is a mutable dict."],"tags":["fallbacks","batch","value-error","input-validation","langchain-core"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}