mlflow/mlflow · error · MlflowException

Invalid version number: {version}

Error message

Invalid version number: {version}

What it means

delete_prompt_version() coerces the prompt version to an int before delegating to delete_model_version(). If int(version) raises ValueError or TypeError, MLflow throws MlflowException 'Invalid version number: {version}'. This guards the registry backend against malformed version identifiers.

Source

Thrown at mlflow/store/model_registry/abstract_store.py:910

        except Exception:
            return None

    def delete_prompt_version(self, name: str, version: str | int) -> None:
        """
        Delete a specific prompt version.

        Default implementation: deletes the underlying ModelVersion.
        Other store implementations may override this method.

        Args:
            name: Name of the prompt.
            version: Version number to delete.
        """
        # Convert version to int if needed
        try:
            version_int = int(version)
        except (ValueError, TypeError):
            raise MlflowException(f"Invalid version number: {version}")
        return self.delete_model_version(name, version_int)

    def get_prompt_version_by_alias(self, name: str, alias: str) -> PromptVersion | None:
        """
        Get a prompt version by alias.

        Default implementation: uses get_model_version_by_alias and converts to PromptVersion.

        Args:
            name: Name of the prompt.
            alias: Alias name.

        Returns:
            A PromptVersion object, or None if not found.
        """
        return self.get_prompt_version(name, alias)

    def set_prompt_alias(self, name: str, alias: str, version: str | int) -> None:

View on GitHub (pinned to 6a27f2decc)

Solutions

  1. Pass the numeric version string, e.g. '1' instead of 'v1'
  2. Strip non-numeric prefixes from the version string before calling
  3. Access the .version attribute of a PromptVersion entity rather than passing the entity itself
  4. Validate the version is numeric before calling

Example fix

// before
client.delete_prompt_version("my_prompt", "v3")
// after
client.delete_prompt_version("my_prompt", "3")  # or version_obj.version
Defensive patterns

Strategy: validation

Validate before calling

def is_valid_prompt_version(v):
    try:
        int(v)
        return True
    except (ValueError, TypeError):
        return False
if not is_valid_prompt_version(version):
    raise ValueError(f"Numeric version required, got: {version!r}")

Type guard

def is_int_str(v) -> bool:
    return isinstance(v, int) or (isinstance(v, str) and v.isdigit())

Try / catch

from mlflow.exceptions import MlflowException
try:
    client.delete_prompt_version(name, version)
except MlflowException as e:
    if "Invalid version number" in str(e):
        logger.error(f"Bad version {version!r} for {name}: {e}")

Prevention

When it happens

Trigger: Calling client.delete_prompt_version(name, version) with a non-numeric version such as 'v1', '1.0', None, or an object whose __int__ conversion fails.

Common situations: Passing a version string parsed from JSON/config that includes a prefix (e.g. 'version-3'), passing a PromptVersion object instead of its .version field, or passing None after a failed lookup.

Related errors


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