{"record":{"id":"8c13f3cff9c06332","repo":"mlflow/mlflow","slug":"when-starting-a-scorer-provided-sample-rate-must","errorCode":null,"errorMessage":"When starting a scorer, provided sample rate must be a number","messagePattern":"When starting a scorer, provided sample rate must be a number","errorType":"validation","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/genai/scorers/base.py","lineNumber":998,"sourceCode":"                print(f\"Scorer is evaluating {active_scorer.sample_rate * 100}% of traces\")\n\n                # Start scorer with filter to only evaluate specific traces\n                filtered_scorer = scorer.start(\n                    sampling_config=ScorerSamplingConfig(\n                        sample_rate=1.0, filter_string=\"YOUR_FILTER_STRING\"\n                    )\n                )\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 not isinstance(sample_rate, (int, float)):\n            raise MlflowException.invalid_parameter_value(\n                \"When starting a scorer, provided sample rate must be a number\"\n            )\n        if sample_rate <= 0:\n            raise MlflowException.invalid_parameter_value(\n                \"When starting a scorer, provided sample rate must be greater than 0\"\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            )","sourceCodeStart":980,"sourceCodeEnd":1016,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/genai/scorers/base.py#L980-L1016","documentation":"Scorer.start() registers/starts a scorer with a sampling configuration. Before persisting, it validates that sampling_config.sample_rate is numeric (int or float). A non-numeric value (e.g., a string like \"0.5\" or None) raises this MlflowException.invalid_parameter_value. The check exists because sample_rate drives server-side trace sampling math.","triggerScenarios":"Calling scorer.start(...) or constructing/submitting a ScorerSamplingConfig(sample_rate=\"0.5\") where sample_rate is a str, None, bool-decoded JSON string, Decimal, or other non-int/float type.","commonSituations":"Loading config from YAML/env vars where sample_rate arrives as a string; passing None when the field was never set; JSON deserialization producing strings; users confusing sample_rate with a percentage string.","solutions":["Pass sample_rate as an int or float, e.g. scorer.start(sample_rate=0.5) not \"0.5\".","Coerce before calling: float(cfg[\"sample_rate\"]) with a try/except ValueError.","If sample_rate may be absent, set an explicit default numeric value (e.g., 1.0) instead of None."],"exampleFix":"// before\nscorer.start(sampling_config=ScorerSamplingConfig(sample_rate=\"0.5\"))\n// after\nscorer.start(sampling_config=ScorerSamplingConfig(sample_rate=0.5))","handlingStrategy":"type-guard","validationCode":"def valid_sample_rate(rate) -> bool:\n    return isinstance(rate, (int, float)) and not isinstance(rate, bool)\n\nif not valid_sample_rate(cfg.get(\"sample_rate\")):\n    raise ValueError(\"sample_rate must be int/float before calling start()\")","typeGuard":"def is_sample_rate(v) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool)","tryCatchPattern":"try:\n    scorer.start(sample_rate=rate)\nexcept MlflowException as e:\n    if \"sample rate must be a number\" in str(e):\n        scorer.start(sample_rate=float(rate))\n    else:\n        raise","preventionTips":["Cast config values loaded from YAML/env/JSON to float before use","Never pass sample_rate as a string or None to start()","Validate sampling config in a shared helper used by all pipelines"],"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"}