@@ -1005,6 +1005,49 @@ def get_termination_reason(self) -> str:
10051005 return str (reason )
10061006 return "unknown"
10071007
1008+ def to_dict (self ) -> Dict [str , Any ]:
1009+ """Serialize this EvaluationRow to a dictionary.
1010+
1011+ The entire EvaluationRow is serialized to JSON, allowing full reconstruction.
1012+ Additional scalar fields are included for convenient filtering/grouping.
1013+
1014+ Returns:
1015+ Dictionary with 'data_json' containing the full serialized row,
1016+ plus convenience fields for filtering.
1017+ """
1018+ return {
1019+ "data_json" : self .model_dump_json (),
1020+ "row_id" : self .input_metadata .row_id if self .input_metadata else None ,
1021+ "score" : self .evaluation_result .score if self .evaluation_result else None ,
1022+ "message_count" : len (self .messages ),
1023+ "has_tools" : bool (self .tools ),
1024+ "created_at" : self .created_at .isoformat () if self .created_at else None ,
1025+ }
1026+
1027+ @classmethod
1028+ def from_dict (cls , data : Dict [str , Any ]) -> "EvaluationRow" :
1029+ """Reconstruct an EvaluationRow from a dictionary.
1030+
1031+ Args:
1032+ data: Dictionary containing 'data_json' with the serialized EvaluationRow.
1033+
1034+ Returns:
1035+ Reconstructed EvaluationRow instance.
1036+
1037+ Raises:
1038+ ValueError: If 'data_json' is missing or invalid.
1039+ """
1040+ from pydantic import ValidationError
1041+
1042+ data_json = data .get ("data_json" )
1043+ if not data_json :
1044+ raise ValueError ("Missing 'data_json' field in dictionary" )
1045+
1046+ try :
1047+ return cls .model_validate_json (data_json )
1048+ except ValidationError as e :
1049+ raise ValueError (f"Failed to deserialize EvaluationRow: { e } " ) from e
1050+
10081051 def __hash__ (self ) -> int :
10091052 # Use a stable hash that works across Python processes
10101053 return self ._stable_hash ()
0 commit comments