@@ -445,9 +445,6 @@ def upload_scores(self, rows: List[EvaluationRow], model_name: str, mean_score:
445445 rows: List of EvaluationRow objects with session_data containing trace IDs
446446 model_name: Name of the model (used as the score name in Langfuse)
447447 mean_score: The calculated mean score to push to Langfuse
448-
449- Note:
450- Silently handles errors if rows lack session data
451448 """
452449 try :
453450 for trace_id in set (
@@ -464,6 +461,31 @@ def upload_scores(self, rows: List[EvaluationRow], model_name: str, mean_score:
464461 except Exception as e :
465462 logger .warning ("Failed to push scores to Langfuse: %s" , e )
466463
464+ def upload_score (self , row : EvaluationRow , model_name : str ) -> None :
465+ """Upload evaluation score for a single row back to Langfuse.
466+
467+ Args:
468+ row: Single EvaluationRow with evaluation_result and session_data containing trace ID
469+ model_name: Name of the model (used as the score name in Langfuse)
470+ """
471+ try :
472+ if (
473+ row .evaluation_result
474+ and row .evaluation_result .is_score_valid
475+ and row .input_metadata
476+ and row .input_metadata .session_data
477+ and "langfuse_trace_id" in row .input_metadata .session_data
478+ ):
479+ trace_id = row .input_metadata .session_data ["langfuse_trace_id" ]
480+ if trace_id :
481+ self .client .create_score (
482+ trace_id = trace_id ,
483+ name = model_name ,
484+ value = row .evaluation_result .score ,
485+ )
486+ except Exception as e :
487+ logger .warning ("Failed to push score to Langfuse: %s" , e )
488+
467489
468490def create_langfuse_adapter () -> LangfuseAdapter :
469491 """Factory function to create a Langfuse adapter."""
0 commit comments