{"record":{"id":"b9f776651584059b","repo":"Lightning-AI/pytorch-lightning","slug":"you-provided-multiple-stage-dataloader-prefix-d","errorCode":null,"errorMessage":"You provided multiple `{stage.dataloader_prefix}_dataloader`, but no `dataloader_idx` argument in `{type(pl_module).__name__}.{hook}()`. Try adding `dataloader_idx=0` to its signature.","messagePattern":"You provided multiple `(.+?)_dataloader`, but no `dataloader_idx` argument in `(.+?)\\.(.+?)\\(\\)`\\. Try adding `dataloader_idx=0` to its signature\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/loops/utilities.py","lineNumber":201,"sourceCode":"\ndef _verify_dataloader_idx_requirement(\n    hooks: tuple[str, ...], is_expected: bool, stage: RunningStage, pl_module: \"pl.LightningModule\"\n) -> None:\n    for hook in hooks:\n        fx = getattr(pl_module, hook)\n        # this validation only works if \"dataloader_idx\" is used, no other names such as \"dl_idx\"\n        param_present = is_param_in_hook_signature(fx, \"dataloader_idx\")\n        if not is_expected:\n            if param_present:\n                params = inspect.signature(fx).parameters\n                if \"dataloader_idx\" in params and params[\"dataloader_idx\"].default is inspect.Parameter.empty:\n                    raise RuntimeError(\n                        f\"You provided only a single `{stage.dataloader_prefix}_dataloader`, but have included \"\n                        f\"`dataloader_idx` in `{type(pl_module).__name__}.{hook}()`. Either remove the\"\n                        \" argument or give it a default value i.e. `dataloader_idx=0`.\"\n                    )\n        elif not param_present:\n            raise RuntimeError(\n                f\"You provided multiple `{stage.dataloader_prefix}_dataloader`, but no `dataloader_idx`\"\n                f\" argument in `{type(pl_module).__name__}.{hook}()`. Try adding `dataloader_idx=0` to its\"\n                \" signature.\"\n            )\n","sourceCodeStart":183,"sourceCodeEnd":206,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/loops/utilities.py#L183-L206","documentation":"Raised by _verify_dataloader_idx_requirement when multiple dataloaders were provided (is_expected True) but the matching step hook has no `dataloader_idx` parameter. With multiple loaders Lightning must tell the model which loader a batch came from; without the parameter the hook cannot receive it.","triggerScenarios":"`def training_step(self, batch, batch_idx):` with `trainer.fit(model, [dl1, dl2])` or a datamodule whose train_dataloader returns a list; same for validation_step/test_step/predict_step with multiple loaders.","commonSituations":"Adding a second val/train dataloader later without updating the LightningModule; using built-in multi-val-dataloader examples but copying a single-loader step signature.","solutions":["Add the parameter with a default: `def training_step(self, batch, batch_idx, dataloader_idx=0)`","Or reduce to a single dataloader / merge datasets with ConcatDataset if per-loader identity is unneeded"],"exampleFix":"# before\ndef training_step(self, batch, batch_idx):\n    ...\ntrainer.fit(model, [dl1, dl2])\n\n# after\ndef training_step(self, batch, batch_idx, dataloader_idx=0):\n    ...\ntrainer.fit(model, [dl1, dl2])","handlingStrategy":"validation","validationCode":"import inspect\n\nmulti = isinstance(dataloaders, (list, tuple)) and len(dataloaders) > 1\nif multi:\n    assert 'dataloader_idx' in inspect.signature(model.training_step).parameters","typeGuard":"def has_dataloader_idx(fn) -> bool:\n    return 'dataloader_idx' in inspect.signature(fn).parameters","tryCatchPattern":null,"preventionTips":["Add `dataloader_idx=0` to step hooks whenever multiple dataloaders may be used","Keep hook signatures in sync with datamodule loader lists via a shared config"],"tags":["pytorch-lightning","dataloader-idx","hook-signature","multi-dataloader"],"backgroundTag":"hook-signature-mismatch","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}