{"record":{"id":"76971d3f83a87f76","repo":"PaddlePaddle/PaddleOCR","slug":"the-input-data-is-inconsistent-with-expectations","errorCode":null,"errorMessage":"The input data is inconsistent with expectations.","messagePattern":"The input data is inconsistent with expectations\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"deploy/hubserving/kie_ser/module.py","lineNumber":115,"sourceCode":"                continue\n            images.append(img)\n        return images\n\n    def predict(self, images=[], paths=[]):\n        \"\"\"\n        Get the chinese texts in the predicted images.\n        Args:\n            images (list(numpy.ndarray)): images data, shape of each is [H, W, C]. If images not paths\n            paths (list[str]): The paths of images. If paths not images\n        Returns:\n            res (list): The result of chinese texts and save path of images.\n        \"\"\"\n        if images != [] and isinstance(images, list) and paths == []:\n            predicted_data = images\n        elif images == [] and isinstance(paths, list) and paths != []:\n            predicted_data = self.read_images(paths)\n        else:\n            raise TypeError(\"The input data is inconsistent with expectations.\")\n\n        assert (\n            predicted_data != []\n        ), \"There is not any image to be predicted. Please check the input data.\"\n\n        all_results = []\n        for img in predicted_data:\n            if img is None:\n                logger.info(\"error in loading image\")\n                all_results.append([])\n                continue\n            starttime = time.time()\n            ser_res, _, elapse = self.ser_predictor(img)\n            elapse = time.time() - starttime\n            logger.info(\"Predict time: {}\".format(elapse))\n            all_results.append(ser_res)\n        return all_results\n","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/deploy/hubserving/kie_ser/module.py#L97-L133","documentation":"Raised as TypeError by the kie_ser hub module's predict() when the arguments match neither accepted shape: a non-empty images list with paths == [], or images == [] with a non-empty paths list. Passing both, neither, non-list values, or None (None != [] is True but isinstance(None, list) is False) all fail the exclusive-or style check. It is an input-contract error on the hub HTTP predict handler.","triggerScenarios":"POSTing {\"images\": null, \"paths\": null} or {\"images\": [...], \"paths\": [...]} to the hub endpoint; sending a single numpy array instead of a list; passing a string path in images; empty lists on both sides; a dict payload the handler forwards verbatim.","commonSituations":"Client code copying the OCR (det+rec) hub client but omitting the paths field default; JSON clients sending null instead of []; sending base64 strings where the module expects decoded ndarrays.","solutions":["Send exactly one input form: {\"images\": [ndarray, ...], \"paths\": []} or {\"images\": [], \"paths\": [\"/data/a.jpg\", ...]}","Ensure both fields are JSON arrays (never null) in the request body","Decode base64 images to numpy arrays (cv2.imdecode) before calling the python API","Verify at least one element is present in the chosen list"],"exampleFix":"# before\nres = module.predict(images=None, paths=None)  # TypeError\n\n# after\nres = module.predict(images=[], paths=[\"/data/invoice_01.jpg\"])\n# or\nres = module.predict(images=[img_ndarray], paths=[])","handlingStrategy":"validation","validationCode":"def valid_predict_input(images, paths) -> bool:\n    images_ok = isinstance(images, list) and len(images) > 0\n    paths_ok = isinstance(paths, list) and len(paths) > 0\n    return (images_ok and paths == []) or (paths_ok and images == [])\n\nassert valid_predict_input(images, paths), \"pass exactly one of images/paths as non-empty lists\"","typeGuard":"from typing import Any\n\ndef is_predict_payload(data: Any) -> bool:\n    images = data.get(\"images\") if isinstance(data, dict) else None\n    paths = data.get(\"paths\") if isinstance(data, dict) else None\n    if not (isinstance(images, list) and isinstance(paths, list)):\n        return False\n    return bool(images) != bool(paths)  # exactly one non-empty","tryCatchPattern":"try:\n    results = module.predict(images=images, paths=paths)\nexcept TypeError as e:\n    if \"inconsistent with expectations\" in str(e):\n        # normalize inputs and retry with exactly one form\n        results = module.predict(images=[], paths=[str(p) for p in paths or []])\n    else:\n        raise","preventionTips":["Always send both keys as JSON arrays, defaulting the unused one to []","Decode base64 to ndarrays before calling the python API","Wrap hub HTTP handlers with a payload schema check"],"tags":["api","validation","python","hubserving","input-contract"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}