Skip to main content

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, or enum
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:
Always use the same subject when executing prompts and recording metrics. This ensures metrics are correctly attributed to the right prompt version.

Response Object

The record method returns a result object:

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

Best Practices

Always use the same subject for prompt execution and metric recording to ensure proper aggregation.
Consider recording metrics in a background task to avoid blocking your main application flow.
Don’t let metric recording failures break your application. Use try/except blocks and log errors.
Use the right metric type for your use case:
  • Float for numerical measurements
  • Boolean for yes/no tracking
  • Enum for categorical data
Create metric definitions in the dashboard before recording metrics in your code.

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