mlflow/mlflow · error · MlflowException

INVALID_PARAMETER_VALUE

INVALID_PARAMETER_VALUE

Error message

Failed to copy the specified code path '{code_path}' into the model artifacts. It appears that your code path includes file(s) that cannot be copied{example}. Please specify a code path that does not include such files and try again.

What it means

MLflow raises this MlflowException (INVALID_PARAMETER_VALUE) when copying a `code_paths` entry into the model artifacts fails with an OSError inside `_validate_and_copy_code_paths`. The underlying OS copy failed—typically because the path includes objects that cannot be copied like Databricks Notebook files, unreadable files, or broken symlinks.

Source

Thrown at mlflow/utils/model_utils.py:202

    can later be used to log custom code as an artifact.

    Args:
        code_paths: A list of files or directories containing code that should be logged
            as artifacts.
        path: The local model path.
        default_subpath: The default directory name used to store code artifacts.
    """
    _validate_code_paths(code_paths)
    if code_paths is not None:
        code_dir_subpath = default_subpath
        for code_path in code_paths:
            try:
                _copy_file_or_tree(src=code_path, dst=path, dst_dir=code_dir_subpath)
            except OSError as e:
                # A common error is code-paths includes Databricks Notebook. We include it in error
                # message when running in Databricks, but not in other envs tp avoid confusion.
                example = ", such as Databricks Notebooks" if is_in_databricks_runtime() else ""
                raise MlflowException(
                    message=(
                        f"Failed to copy the specified code path '{code_path}' into the model "
                        "artifacts. It appears that your code path includes file(s) that cannot "
                        f"be copied{example}. Please specify a code path that does not include "
                        "such files and try again.",
                    ),
                    error_code=INVALID_PARAMETER_VALUE,
                ) from e
    else:
        code_dir_subpath = None
    return code_dir_subpath


def _infer_and_copy_code_paths(flavor, path, default_subpath="code"):
    # Capture all imported modules with full module name during loading model.
    modules = _capture_imported_modules(path, flavor, record_full_module=True)

    all_modules = set(modules)

View on GitHub (pinned to 6a27f2decc)

Solutions

  1. Remove non-copyable entries (e.g., Databricks Notebooks) from code_paths; point to regular .py files/directories only.
  2. Check read permissions on each code_paths entry.
  3. Verify each path exists and is a regular file or directory before saving.
  4. If you need notebook code, extract it into a .py module first.

Example fix

# before
code_paths=["utils.py", "My Notebook"]  # notebook can't be copied
# after
code_paths=["utils.py", "notebook_logic.py"]  # extracted plain module
Defensive patterns

Strategy: validation

Validate before calling

import os
bad = [p for p in (code_paths or []) if not os.path.exists(p) or not (os.path.isfile(p) or os.path.isdir(p))]
assert not bad, f"Non-copyable or missing code paths: {bad}"

Type guard

def is_copyable_path(p):
    import os
    return os.path.exists(p) and (os.path.isfile(p) or os.path.isdir(p)) and not os.path.islink(p) or not os.path.islink(p)

Try / catch

from mlflow.exceptions import MlflowException
try:
    mlflow.sklearn.save_model(model, path, code_paths=code_paths)
except MlflowException as e:
    if "Failed to copy the specified code path" in str(e):
        clean_paths = [p for p in code_paths if os.path.isfile(p) or os.path.isdir(p)]
        mlflow.sklearn.save_model(model, path, code_paths=clean_paths)
    else:
        raise

Prevention

When it happens

Trigger: Including a Databricks Notebook in code_paths while running in Databricks; code_paths entry points to a file with no read permission; copying across filesystems with unsupported features; path disappearing mid-copy.

Common situations: Notebook-driven MLflow development on Databricks where the notebook itself is in code_paths; pip-installed or root-only files; network-mounted code directories that drop out during save.

Related errors


AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29). Data as JSON: /api/errors/ae6776b6a6eee604. Report an issue: GitHub.