{"record":{"id":"a174bc67424e9e31","repo":"Lightning-AI/pytorch-lightning","slug":"the-expected-response-response-doesn-t-match-the","errorCode":null,"errorMessage":"The expected response {response} doesn't match the generated one {self.resp.json()}.","messagePattern":"The expected response (.+?) doesn't match the generated one (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/serve/servable_module_validator.py","lineNumber":125,"sourceCode":"                resp = requests.get(f\"http://{self.host}:{self.port}/ping\")\n                ready = resp.status_code == 200\n            if time.time() - t0 > self.timeout:\n                process.kill()\n                raise Exception(f\"The server didn't start within {self.timeout} seconds.\")\n            time.sleep(0.1)\n\n        payload = servable_module.configure_payload()\n\n        if \"body\" not in payload:\n            raise Exception(f'Your provided payload {payload} should have a field named \"body\".')\n\n        self.resp = requests.post(f\"http://{self.host}:{self.port}/serve\", json=payload)\n        process.kill()\n\n        if is_overridden(\"configure_response\", servable_module, ServableModule):\n            response = servable_module.configure_response()\n            if self.resp.json() != response:\n                raise Exception(f\"The expected response {response} doesn't match the generated one {self.resp.json()}.\")\n\n        if self.exit_on_failure and not self.successful:\n            raise MisconfigurationException(\"The model isn't servable. Investigate the traceback and try again.\")\n\n        if self.successful:\n            _logger.info(f\"Your model is servable and the received payload was {self.resp.json()}.\")\n\n    @property\n    def successful(self) -> Optional[bool]:\n        \"\"\"Returns whether the model was successfully served.\"\"\"\n        return self.resp.status_code == 200 if self.resp else None\n\n    @override\n    def state_dict(self) -> dict[str, Any]:\n        return {\"successful\": self.successful, \"optimization\": self.optimization, \"server\": self.server}\n\n    @staticmethod\n    def _start_server(servable_model: ServableModule, host: str, port: int, _: bool) -> None:","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/serve/servable_module_validator.py#L107-L143","documentation":"If the model overrides configure_response, the validator compares the actual HTTP response JSON with the model's declared expected response. A mismatch (different values, keys, or JSON-serialized types) raises a generic Exception listing both dicts.","triggerScenarios":"Overriding configure_response with hardcoded expected values that don't match serve_step output after serialization (e.g. tensors serialized to nested lists, float precision differences, extra/missing keys).","commonSituations":"Updating model logic but forgetting to update configure_response; expecting a tensor repr while the serializer returned a Python list; dtype/rounding differences between local run and served run.","solutions":["Run once without overriding configure_response, inspect self.resp.json() in logs, then set configure_response to exactly that structure","Compare key sets and serialized types (lists vs numbers) — not tensor objects","Use approximations (round/pytest.approx-style tolerance) instead of exact equality if floats differ"],"exampleFix":"// before\ndef configure_response(self):\n    return {\"output\": tensor([1.0, 2.0])}  # tensor, not JSON-serializable form\n// after\ndef configure_response(self):\n    return {\"output\": [1.0, 2.0]}","handlingStrategy":"validation","validationCode":"from lightning.pytorch.utilities import is_overridden\nfrom lightning.pytorch.serve import ServableModule\n\nif is_overridden(\"configure_response\", model, ServableModule):\n    expected = model.configure_response()\n    assert isinstance(expected, dict), \"expected response must be a JSON-compatible dict\"","typeGuard":null,"tryCatchPattern":"try:\n    trainer.fit(model)\nexcept Exception as e:\n    if \"doesn't match the generated one\" in str(e):\n        # log self.resp.json() structure and align configure_response\n        print(e)","preventionTips":["Derive configure_response from an observed run rather than hand-writing it","Use JSON-primitive values (lists/numbers) only"],"tags":["lightning","serving","response-mismatch","assertion"],"backgroundTag":"response-schema-mismatch","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}