mlflow/mlflow · error · MlflowException

INVALID_PARAMETER_VALUE

INVALID_PARAMETER_VALUE

Error message

Failed to find answer similarity metric for version {metric_version}. Please check the version

What it means

answer_similarity() imports mlflow.metrics.genai.prompts.<metric_version>.AnswerSimilarityMetric by class name derived from metric_version. If that module does not exist (ModuleNotFoundError), MLflow raises INVALID_PARAMETER_VALUE telling you to check the version.

Source

Thrown at mlflow/metrics/genai/metric_definitions.py:69

            the default parameters defined in the metric implementation.
        extra_headers: (Optional) Dictionary of extra headers to be passed to the judge model.
        proxy_url: (Optional) Proxy URL to be used for the judge model. This is useful when the
            judge model is served via a proxy endpoint, not directly via LLM provider services.
            If not specified, the default URL for the LLM provider will be used
            (e.g., https://api.openai.com/v1/chat/completions for OpenAI chat models).
        max_workers: (Optional) The maximum number of workers to use for judge scoring.
            Defaults to 10 workers.

    Returns:
        A metric object
    """
    if metric_version is None:
        metric_version = _get_latest_metric_version()
    class_name = f"mlflow.metrics.genai.prompts.{metric_version}.AnswerSimilarityMetric"
    try:
        answer_similarity_class_module = _get_class_from_string(class_name)
    except ModuleNotFoundError:
        raise MlflowException(
            f"Failed to find answer similarity metric for version {metric_version}."
            f" Please check the version",
            error_code=INVALID_PARAMETER_VALUE,
        ) from None
    except Exception as e:
        raise MlflowException(
            f"Failed to construct answer similarity metric {metric_version}. Error: {e!r}",
            error_code=INTERNAL_ERROR,
        ) from None

    if examples is None:
        examples = answer_similarity_class_module.default_examples
    if model is None:
        model = answer_similarity_class_module.default_model

    return make_genai_metric(
        name="answer_similarity",
        definition=answer_similarity_class_module.definition,

View on GitHub (pinned to 6a27f2decc)

Solutions

  1. Run mlflow.__version__ and use a metric_version that exists in mlflow/metrics/genai/prompts/ of that install
  2. Omit metric_version to use _get_latest_metric_version()'s default
  3. Upgrade mlflow if you need a newer prompt version
  4. Fix case/typo in the version string (versions are lowercase like 'v1')

Example fix

// before
answer_similarity(metric_version="V2", model="openai:/gpt-4o-mini")
// after
answer_similarity(metric_version="v1", model="openai:/gpt-4o-mini")
Defensive patterns

Strategy: validation

Validate before calling

import mlflow, importlib.util
if metric_version and not importlib.util.find_spec(f"mlflow.metrics.genai.prompts.{metric_version}"):
    raise ValueError(f"metric_version {metric_version} not in mlflow {mlflow.__version__}")

Type guard

def known_metric_version(v):
    return v is None or (isinstance(v, str) and importlib.util.find_spec(f"mlflow.metrics.genai.prompts.{v}") is not None)

Try / catch

from mlflow.exceptions import MlflowException
try:
    m = answer_similarity(metric_version=v, model=model)
except MlflowException as e:
    if e.error_code == "INVALID_PARAMETER_VALUE":
        m = answer_similarity(model=model)  # fall back to latest default
    else:
        raise

Prevention

When it happens

Trigger: Calling answer_similarity(metric_version='vX') where prompts/vX does not exist — a typo like 'V1' vs 'v1', a version from docs of a newer MLflow, or metric_version=None defaulting to a version not present in the installed mlflow.

Common situations: Following a blog/tutorial referencing a prompt version not in your installed mlflow; downgrading mlflow while keeping code that names a newer version; case typos in the version string.

Related errors


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