BuiltInMetrics
Provides convenient access to built-in Galileo metrics (formerly “scorers”). Examples from galileo.metric import MetricAccess built-in metrics
Metric.metrics.correctness Metric.metrics.completeness Metric.metrics.toxicityMetric
Base class for all Galileo metrics. This is an abstract base class that defines common attributes and methods for all metric types. Use one of the concrete metric classes instead:- GalileoMetric: Built-in Galileo scorers (access via Metric.scorers)
- LlmMetric: Custom LLM-based metrics with prompt templates
- LocalMetric: Local function-based metrics
- CodeMetric: Code-based metrics (future support)
Common Attributes
id (str | None): The unique metric identifier (UUID). name (str): The metric name. scorer_type (ScorerTypes | None): The type of scorer. description (str): Description of the metric. tags (list[str]): Tags associated with the metric. created_at (datetime | None): When the metric was created. updated_at (datetime | None): When the metric was last updated. version (int | None): Metric version number.Class Attributes
metrics (BuiltInMetrics): Access built-in Galileo metrics. Examples1. Use built-in Galileo scorers
from galileo import Metric, GalileoMetric, LlmMetric, LocalMetric, LogStream log_stream = LogStream.get(name=“my-stream”, project_name=“my-project”) log_stream.set_metrics([ Metric.metrics.correctness, Metric.metrics.completeness, ])2. Create custom LLM metric
llm_metric = LlmMetric( name=“response_quality”, prompt=“Rate the quality…”, model=“gpt-4o-mini”, judges=3, ).create()3. Create local function-based metric
def my_scorer(trace_or_span): return 0.5 local_metric = LocalMetric( name=“response_length”, scorer_fn=my_scorer, )delete
delete_by_name
Metric.get(name=...).delete()
when you only need to delete and don’t need the metric object.
Arguments
name: The name of the metric to delete.
get
id: The metric ID (UUID).name: The metric name.
list
name_filter: Filter metrics by exact name match.scorer_types: Filter by scorer types.
refresh
to_legacy_metric
Use with existing APIs
update
name, description, and tags can be updated via this method.
On success the instance is updated with the API response and returned in SYNCED state.
Arguments
**kwargs(Any): Fields to update. Supported keys:name,description,tags.
LlmMetric
LLM-based metric with custom prompt templates. This metric type allows you to create custom metrics evaluated by an LLM judge using a prompt template. Arguments-
Configuration: -
-------------: Default values formodelandjudgescan be configured via:- Configuration.default_scorer_model (env: GALILEO_DEFAULT_SCORER_MODEL)
- Configuration.default_scorer_judges (env: GALILEO_DEFAULT_SCORER_JUDGES)
Create custom LLM metric with string model name
metric = LlmMetric( name=“response_quality”, prompt=''' Rate the quality of this response on a scale of 1-10. Question: Answer: Return only the numerical score (1-10). ''', model=“gpt-4o-mini”, # String model name judges=3, node_level=StepType.llm, description=“Rates response quality”, tags=[“quality”, “custom”], output_type=OutputTypeEnum.PERCENTAGE, cot_enabled=True, ).create()Or use a Model object from Integration
from galileo.integration import Integration gpt_model = Integration.openai.get_model(alias=“gpt-4o-mini”) metric = LlmMetric( name=“response_quality”, prompt=“Rate quality 1-10: -> ”, model=gpt_model, # Model object judges=3, ).create()create
CodeMetric
Code-based metric. This metric type is for code-based scorers that execute custom code to evaluate traces/spans. ExamplesGet existing code metric
metric = Metric.get(name=“my-code-metric”) assert isinstance(metric, CodeMetric)Create code metric with inline code
metric = CodeMetric( name=“custom_code_scorer”, code=“def scorer_fn(step_object):\n return 1.0”, description=“Custom code-based scorer”, tags=[“custom”, “code”], node_level=StepType.llm, output_type=OutputTypeEnum.PERCENTAGE, ).create()Load code from file
metric = CodeMetric( name=“custom_code_scorer”, node_level=StepType.llm, ).load_code(”./scorers/my_scorer.py”).create()create
Create with inline code
metric = CodeMetric( name=“custom_code_scorer”, code=“def scorer_fn(step_object):\n return 1.0”, node_level=StepType.llm, ).create() assert metric.is_synced()Create by loading from file
metric = CodeMetric( name=“custom_code_scorer”, node_level=StepType.llm, ).load_code(”./scorers/my_scorer.py”).create() assert metric.is_synced()load_code
code_file_path: Path to the Python file containing the scorer code.
GalileoMetric
Built-in Galileo scorer metric. This metric type represents Galileo’s built-in scorers like correctness, completeness, toxicity, etc. Access these viaMetric.metrics.
Examples