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
- An optional success flag indicating if this metric evaluation was successful
Deprecated Output Types
The RewardOutput
and MetricRewardOutput
classes are deprecated and will be removed in a future version:
Type Conversion
The Reward Kit provides built-in methods for converting between types:
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 Flags: Set the success flag in MetricResult to indicate pass/fail conditions
- 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