Overview
Custom metrics enable:- Domain-specific evaluation: Track metrics relevant to your use case
- Partial credit: Reward partial success
- Multi-dimensional scoring: Combine multiple criteria
- Statistical analysis: Compute percentiles, distributions, etc.
Built-in Metrics
Harbor includes several built-in metrics:Creating Custom Metrics
Method 1: Python Class
Implement theBaseMetric interface:
metrics/custom_metric.py
Method 2: UvScript
For simpler metrics, use inline Python:job-config.yaml
UvScript metrics receive a
trials list with all trial results and must set a result variable.Example Custom Metrics
Percentile Metrics
Weighted Metrics
Cost Efficiency
Time-Based Metrics
Multi-Metric Evaluation
Track multiple metrics simultaneously:job-config.yaml
Category-Specific Metrics
Track metrics per category:Best Practices
- Handle edge cases: Empty trials, missing metadata, etc.
- Reset properly: Clear state between jobs
- Document behavior: Explain what your metric measures
- Type hints: Use proper type annotations
- Test thoroughly: Validate on sample data first
- Consider efficiency: Avoid expensive computations in
update() - Return appropriate types: Float for scalar, dict for breakdowns
Debugging Metrics
Test metric implementation:Advanced: Confidence Intervals
Next Steps
Verifiers
Learn about reward generation
Parameter Sweeps
Use metrics in sweeps
Job Results
Understand result structure
BaseMetric API
Full metric API reference