Overview
Metrics let you measure how well your prompts perform. When you record metrics with the same subject used for prompt execution, Switchport automatically aggregates them per prompt version.Basic Usage
Record a metric:Metric Types
Switchport supports three types of metrics:Float Metrics
Numerical values (e.g., ratings, scores, response times):Boolean Metrics
True/false values (e.g., conversions, success rates):Enum Metrics
Categorical values (e.g., sentiment, outcome):Creating Metric Definitions
Before recording metrics, create a metric definition in the dashboard:1
Navigate to Metrics
Go to Metrics → New Metric in the dashboard
2
Configure the metric
- Key: Unique identifier (e.g.,
satisfaction) - Name: Human-readable name (e.g., “User Satisfaction”)
- Type:
float,boolean, orenum
3
Create
Click Create to save the metric definition
Linking Metrics to Prompts
To link metrics to prompt versions, use the same subject for both:Custom Timestamps
You can provide a custom timestamp for metrics:nil, the current time is used.
Response Object
TheRecord method returns a MetricRecordResponse:
Error Handling
Handle common errors when recording metrics:Common Patterns
Pattern 1: User Feedback
Pattern 2: Conversion Tracking
Pattern 3: Email Campaign
Pattern 4: Multi-Metric Tracking
Pattern 5: Goroutine for Async Recording
Best Practices
Use the same subject
Use the same subject
Always use the same subject for prompt execution and metric recording to ensure proper aggregation.
Record metrics asynchronously
Record metrics asynchronously
Consider recording metrics in a goroutine to avoid blocking your main application flow.
Handle failures gracefully
Handle failures gracefully
Don’t let metric recording failures break your application. Use error handling and logging.
Choose appropriate metric types
Choose appropriate metric types
Use the right metric type for your use case:
- Float (or int) for numerical measurements
- Boolean for yes/no tracking
- String for categorical data (enum)
Define metrics early
Define metrics early
Create metric definitions in the dashboard before recording metrics in your code.
Use type-safe wrappers
Use type-safe wrappers
Consider creating wrapper functions with specific types for your metrics to avoid interface everywhere.
Viewing Metrics
Metrics are automatically aggregated per prompt version in the dashboard. You can:- View average values for float metrics
- View success rates for boolean metrics
- View distribution for enum metrics
- Compare metrics across different prompt versions
- Identify winning versions based on metric performance
Next Steps
A/B Testing
Learn how to run A/B tests with metrics
API Reference
See the full metrics API reference

