{"record":{"id":"f5757bbc4b347050","repo":"mlflow/mlflow","slug":"when-updating-a-scorer-provided-sample-rate-must","errorCode":null,"errorMessage":"When updating a scorer, provided sample rate must be a number","messagePattern":"When updating a scorer, provided sample rate must be a number","errorType":"validation","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/genai/scorers/base.py","lineNumber":1090,"sourceCode":"                )\n                print(f\"Updated sample rate: {updated_scorer.sample_rate}\")\n\n                # Update to add filtering criteria\n                filtered_scorer = updated_scorer.update(\n                    sampling_config=ScorerSamplingConfig(filter_string=\"YOUR_FILTER_STRING\")\n                )\n                print(f\"Added filter: {filtered_scorer.filter_string}\")\n        \"\"\"\n        from mlflow.genai.scorers.registry import (\n            DatabricksStore,\n            _get_scorer_store,\n        )\n\n        self._check_can_be_registered()\n\n        sample_rate = sampling_config.sample_rate\n        if sample_rate is not None and not isinstance(sample_rate, (int, float)):\n            raise MlflowException.invalid_parameter_value(\n                \"When updating a scorer, provided sample rate must be a number\"\n            )\n\n        scorer_name = name or self.name\n        store = _get_scorer_store()\n\n        if isinstance(store, DatabricksStore):\n            return store.update_registered_scorer(\n                name=scorer_name,\n                scorer=self,\n                sample_rate=sample_rate,\n                filter_string=sampling_config.filter_string,\n                experiment_id=experiment_id,\n            )\n\n        # For MLflow backend, use provided experiment_id or fall back to scorer's experiment_id\n        exp_id = experiment_id or self._experiment_id\n        if exp_id is None:","sourceCodeStart":1072,"sourceCodeEnd":1108,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/genai/scorers/base.py#L1072-L1108","documentation":"Scorer.update() validates sampling_config.sample_rate: unlike start, None is allowed (meaning 'unchanged'), but any other non-numeric value raises MlflowException.invalid_parameter_value. This protects the backend from storing a malformed sampling rate during a partial update.","triggerScenarios":"scorer.update(...) with a ScorerSamplingConfig whose sample_rate is a string (\"0.5\"), bool, Decimal, or other non-int/float while not being None.","commonSituations":"Partial-update code paths forwarding raw form/config values; YAML/env-loaded settings arriving as strings; frameworks passing sentinel objects instead of None.","solutions":["Pass either None (leave unchanged) or a numeric int/float value.","Coerce: rate = None if raw is None else float(raw).","Normalize config ingestion (cast at load time) so update() never sees strings."],"exampleFix":"// before\nscorer.update(sampling_config=ScorerSamplingConfig(sample_rate=\"0.25\"))\n// after\nraw = \"0.25\"\nscorer.update(sampling_config=ScorerSamplingConfig(sample_rate=None if raw is None else float(raw)))","handlingStrategy":"type-guard","validationCode":"def normalize_rate(raw):\n    if raw is None:\n        return None\n    if isinstance(raw, str):\n        return float(raw)\n    return raw\n\nscorer.update(sampling_config=ScorerSamplingConfig(sample_rate=normalize_rate(raw)))","typeGuard":"def is_rate_or_none(v) -> bool:\n    return v is None or (isinstance(v, (int, float)) and not isinstance(v, bool))","tryCatchPattern":"try:\n    scorer.update(sampling_config=cfg)\nexcept MlflowException as e:\n    if \"must be a number\" in str(e):\n        scorer.update(sampling_config=ScorerSamplingConfig(sample_rate=float(cfg.sample_rate)))\n    else:\n        raise","preventionTips":["Normalize all sampling-config fields at ingestion time","Treat None as 'leave unchanged' in update paths, not a string placeholder","Add schema validation (pydantic) for scorer update payloads"],"tags":["python","mlflow-genai","validation","type-error"],"backgroundTag":"invalid-parameter-type","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}