Scorer lifecycle management API reference
This feature is in Beta.
This page describes the methods used to implement production monitoring. For a guide to production monitoring on Databricks, see Production monitoring for GenAI.
Scorer instance methods
Scorer.register()
API Reference: Scorer.register
Register a custom scorer function with the server. Used for scorers created with the @scorer
decorator.
@scorer
def custom_scorer(outputs):
return len(str(outputs.get("response", "")))
# Register the custom scorer
my_scorer = custom_scorer.register(name="response_length")
Parameters:
name
(str): Unique name for the scorer within the experiment. Defaults to the existing name of the scorer.
Returns: New Scorer
instance with server registration
Scorer.start()
API Reference: Scorer.start
Begin online evaluation with the specified sampling configuration.
from mlflow.genai.scorers import ScorerSamplingConfig
# Start monitoring with sampling
active_scorer = registered_scorer.start(
sampling_config=ScorerSamplingConfig(
sample_rate=0.5,
filter_string="trace.status = 'OK'"
),
)
Parameters:
name
(str): Name of the scorer. If not provided, defaults to the current name of the scorer.sampling_config
(ScorerSamplingConfig
): Trace sampling configurationsample_rate
(float): Fraction of traces to evaluate (0.0-1.0). Default: 1.0filter_string
(str, optional): MLflow-compatible filter for trace selection
Returns: New Scorer
instance in active state
Scorer.update()
API Reference: Scorer.update
Modify the sampling configuration of an active scorer. This is an immutable operation.
# Update sampling rate (returns new scorer instance)
updated_scorer = active_scorer.update(
sampling_config=ScorerSamplingConfig(
sample_rate=0.8,
),
)
# Original scorer remains unchanged
print(f"Original: {active_scorer.sample_rate}") # 0.5
print(f"Updated: {updated_scorer.sample_rate}") # 0.8
Parameters:
name
(str): Name of the scorer. If not provided, defaults to the current name of the scorer.sampling_config
(ScorerSamplingConfig
): Trace sampling configurationsample_rate
(float): Fraction of traces to evaluate (0.0-1.0). Default: 1.0filter_string
(str, optional): MLflow-compatible filter for trace selection
Returns: New Scorer
instance with updated configuration
Scorer.stop()
API Reference: Scorer.stop
Stop online evaluation by setting sample rate to 0. Keeps the scorer registered.
# Stop monitoring but keep scorer registered
stopped_scorer = active_scorer.stop()
print(f"Sample rate: {stopped_scorer.sample_rate}") # 0
Parameters:
name
(str): Name of the scorer. If not provided, defaults to the current name of the scorer.
Returns: New Scorer
instance with sample_rate=0
Scorer registry functions
mlflow.genai.scorers.get_scorer()
API Reference: get_scorer
Retrieve a registered scorer by name.
from mlflow.genai.scorers import get_scorer
# Get existing scorer by name
existing_scorer = get_scorer(name="safety_monitor")
print(f"Current sample rate: {existing_scorer.sample_rate}")
Parameters:
name
(str): Name of the registered scorer
Returns: Scorer
instance
mlflow.genai.scorers.list_scorers()
List all registered scorers for the current experiment.
from mlflow.genai.scorers import list_scorers
# List all registered scorers
all_scorers = list_scorers()
for scorer in all_scorers:
print(f"Name: {scorer._server_name}")
print(f"Sample rate: {scorer.sample_rate}")
print(f"Filter: {scorer.filter_string}")
Returns: List of Scorer
instances
mlflow.genai.scorers.delete_scorer()
API Reference: delete_scorer
Delete a registered scorer by name.
from mlflow.genai.scorers import delete_scorer
# Delete existing scorer by name
delete_scorer(name="safety_monitor")
Parameters:
name
(str): Name of the registered scorer
Returns: None
Scorer properties
Scorer.sample_rate
Current sampling rate (0.0-1.0). Returns 0 for stopped scorers.
print(f"Sampling {scorer.sample_rate * 100}% of traces")
Scorer.filter_string
Current trace filter string for MLflow trace selection.
print(f"Filter: {scorer.filter_string}")
Configuration classes
ScorerSamplingConfig
API Reference: ScorerSamplingConfig
Data class that holds sampling configuration for a scorer.
from mlflow.genai import ScorerSamplingConfig
config = ScorerSamplingConfig(
sample_rate=0.5,
filter_string="trace.status = 'OK'"
)
Attributes:
sample_rate
(float, optional): Sampling rate between 0.0 and 1.0filter_string
(str, optional): MLflow trace filter
Metric backfill
backfill_scorers()
from databricks.agents.scorers import backfill_scorers, BackfillScorerConfig
job_id = backfill_scorers(
experiment_id="your-experiment-id",
scorers=[
BackfillScorerConfig(scorer=safety_scorer, sample_rate=0.8),
BackfillScorerConfig(scorer=response_length, sample_rate=0.9)
],
start_time=datetime(2024, 1, 1),
end_time=datetime(2024, 1, 31)
)
Parameters:
All parameters are keyword-only.
experiment_id
(str, optional): The ID of the experiment to backfill. If not provided, uses the current experiment contextscorers
(Union[List[BackfillScorerConfig], List[str]], required): List ofBackfillScorerConfig
objects with custom sample rates (if sample_rate is not provided in BackfillScorerConfig, defaults to the registered scorer's sample rate), OR list of scorer names (strings) to use current sample rates from the experiment's scheduled scorers. Cannot be empty.start_time
(datetime, optional): Start time for backfill evaluation. If not provided, no start time constraint is appliedend_time
(datetime, optional): End time for backfill evaluation. If not provided, no end time constraint is applied
Returns: Job ID of the created backfill job for status tracking (str)