To use existing ActiveRecord models as datasets in Leva, include the Leva::Recordable concern. You must implement several methods to define how data is displayed and used for evaluation.
Required/Recommended methods:
ground_truth: Returns a String representing the correct label.index_attributes: Returns a Hash of attributes for the dataset records index view.show_attributes: Returns a Hash of attributes for the dataset record show view.to_llm_context: Returns a Hash of attributes used as context for the LLM during evaluation.to_dspy_context (Optional): Returns a Hash<Symbol, String> for DSPy optimization. All values must be strings. If not defined, it falls back to to_llm_context.
class TextContent < ApplicationRecord
include Leva::Recordable
def ground_truth
expected_label
end
def index_attributes
{ text: text, expected_label: expected_label }
end
def show_attributes
{ text: text, expected_label: expected_label }
end
def to_llm_context
{ text: text, expected_label: expected_label }
end
def to_dspy_context
{ text: text }
end
end