{"record":{"id":"b76d5eac60e7af72","repo":"mlflow/mlflow","slug":"get-raw-model-is-not-implemented-by-the-underlyi","errorCode":null,"errorMessage":"`get_raw_model` is not implemented by the underlying model","messagePattern":"`get_raw_model` is not implemented by the underlying model","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"mlflow/pyfunc/__init__.py","lineNumber":1063,"sourceCode":"        info = {}\n        if self._model_meta is not None:\n            if hasattr(self._model_meta, \"run_id\") and self._model_meta.run_id is not None:\n                info[\"run_id\"] = self._model_meta.run_id\n            if (\n                hasattr(self._model_meta, \"artifact_path\")\n                and self._model_meta.artifact_path is not None\n            ):\n                info[\"artifact_path\"] = self._model_meta.artifact_path\n            info[\"flavor\"] = self._model_meta.flavors[FLAVOR_NAME][\"loader_module\"]\n        return yaml.safe_dump({\"mlflow.pyfunc.loaded_model\": info}, default_flow_style=False)\n\n    def get_raw_model(self):\n        \"\"\"\n        Get the underlying raw model if the model wrapper implemented `get_raw_model` function.\n        \"\"\"\n        if hasattr(self._model_impl, \"get_raw_model\"):\n            return self._model_impl.get_raw_model()\n        raise NotImplementedError(\"`get_raw_model` is not implemented by the underlying model\")\n\n\ndef _get_pip_requirements_from_model_path(model_path: str):\n    req_file_path = os.path.join(model_path, _REQUIREMENTS_FILE_NAME)\n    if not os.path.exists(req_file_path):\n        return []\n\n    return [req.req_str for req in _parse_requirements(req_file_path, is_constraint=False)]\n\n\n@trace_disabled  # Suppress traces while loading model\ndef load_model(\n    model_uri: str,\n    suppress_warnings: bool = False,\n    dst_path: str | None = None,\n    model_config: str | Path | dict[str, Any] | None = None,\n) -> PyFuncModel:\n    \"\"\"","sourceCodeStart":1045,"sourceCodeEnd":1081,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/pyfunc/__init__.py#L1045-L1081","documentation":"`PythonModel.get_raw_model()` raises NotImplementedError when the wrapped model implementation does not define a `get_raw_model` method. MLflow only delegates to the wrapper if `hasattr(self._model_impl, 'get_raw_model')` is true; otherwise there is no raw model to expose and the error is thrown deliberately.","triggerScenarios":"Calling `mlflow.pyfunc.get_raw_model(model_uri)` (or the method on a loaded pyfunc) when the model was logged from a flavor/wrapper that never implemented `get_raw_model`, e.g. a plain custom PythonModel or an older logged model predating the API.","commonSituations":"Using get_raw_model on models logged with custom pyfunc wrappers, on models from older MLflow versions before the API existed, or on flavors that don't wrap a single underlying raw model (e.g. ensembles, pipelines).","solutions":["Load the model and access the underlying object directly via `model._model_impl` or the flavor-specific attribute if you control the code","Unwrap only models whose wrapper explicitly implements `get_raw_model` (check `hasattr` first)","Re-log the model with a current MLflow version and a wrapper that implements `get_raw_model`","If you just need predictions, call `model.predict(...)` instead of unwrapping the raw model"],"exampleFix":"// before\nraw = mlflow.pyfunc.get_raw_model(\"runs:/abc/model\")  # raises for custom wrapper\n// after\nm = mlflow.pyfunc.load_model(\"runs:/abc/model\")\nraw = m.get_raw_model() if hasattr(m._model_impl, \"get_raw_model\") else m._model_impl","handlingStrategy":"type-guard","validationCode":"m = mlflow.pyfunc.load_model(model_uri)\nif not hasattr(m._model_impl, \"get_raw_model\"):\n    raise RuntimeError(\"model wrapper does not support get_raw_model\")","typeGuard":"def has_raw_model(pyfunc_model) -> bool:\n    return hasattr(pyfunc_model._model_impl, \"get_raw_model\")","tryCatchPattern":"try:\n    raw = pyfunc_model.get_raw_model()\nexcept NotImplementedError:\n    raw = pyfunc_model._model_impl  # fallback unwrap","preventionTips":["Check hasattr(model_impl, 'get_raw_model') before calling","Prefer model.predict() unless you truly need the raw object","Keep MLflow and flavor wrappers up to date","Document that custom PythonModel subclasses should implement get_raw_model if unwrapping is expected"],"tags":["pyfunc","not-implemented","model-wrapping"],"backgroundTag":"not-implemented-method","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}