Core data types
Core Data Types
This guide explains the primary data types used in the Reward Kit, including the input and output structures for reward functions.
Overview
The Reward Kit uses several core data types to represent:
- Conversation messages
- Evaluation results
- Component metrics
Understanding these types is crucial for creating effective reward functions.
Message Types
The Message
Class
The Message
class represents a single message in a conversation and is compatible with the OpenAI message format.
Message Dictionary Format
When working with reward functions, messages are often passed as dictionaries:
The minimum required fields are:
role
: The sender of the message ("user"
,"assistant"
, or"system"
)content
: The text content of the message
Additional fields for function/tool calling may include:
name
: Name of the sender (for named system messages)tool_calls
: Tool call informationfunction_call
: Function call information (legacy format)
Evaluation Output Types
EvaluateResult
Class
The EvaluateResult
class represents the complete result of a reward function evaluation, containing:
- An overall score (typically 0.0 to 1.0)
- An optional reason/explanation for the overall score
- A dictionary of component metrics
- An optional error field for handling evaluation failures
MetricResult
Class
The MetricResult
class represents a single component metric in the evaluation, containing:
- A score value (typically 0.0 to 1.0)
- A reason/explanation for the score
- A
success: bool
flag indicating if the metric condition was met (e.g., pass/fail).
Removed Output Types (Legacy)
The RewardOutput
and MetricRewardOutput
classes were used in older versions but have now been fully removed. All reward functions should now use EvaluateResult
and MetricResult
.
If you are migrating from an older version that used RewardOutput
, please refer to the “Migration from RewardOutput to EvaluateResult” section below.
Using Types in Reward Functions
Here’s how to use these types properly in your reward functions:
Best Practices for Data Types
- Use EvaluateResult: Always return EvaluateResult from your reward functions
- Use Type Hints: Include proper type annotations in your functions
- Provide Reasons: Include clear reason strings for both overall score and individual metrics
- Use
success
: Set thesuccess: bool
flag inMetricResult
to indicate pass/fail or whether a specific condition for that metric was met. - Default Values: Provide defaults for optional parameters
- Validation: Validate input data before processing
- Error Handling: Handle missing or malformed data gracefully
- Documentation: Document the expected format for your inputs and outputs
Migration from RewardOutput to EvaluateResult
If you have existing code using RewardOutput, here’s how to migrate to EvaluateResult:
Next Steps
Now that you understand the core data types:
- Learn about Evaluation Workflows for testing and deploying your functions
- Explore Advanced Reward Functions to see these types in action
- Check the API Reference for complete details on all data types