@@ -122,6 +122,54 @@ def _create_empty_extraction_response(
122122 "message" : message ,
123123 }
124124
125+ def _extract_quality_score_from_validation_dict (
126+ self , validation : Dict [str , Any ], doc_id : str
127+ ) -> float :
128+ """Extract quality score from validation dictionary with multiple fallback strategies."""
129+ # Check for overall_score directly (this is the main field from JudgeEvaluation)
130+ quality = validation .get ("overall_score" , 0.0 )
131+
132+ # If not found, check for quality_score field
133+ if quality == 0.0 :
134+ quality = validation .get ("quality_score" , 0.0 )
135+
136+ # If still not found, check nested structures
137+ if quality == 0.0 and "quality_score" in validation :
138+ qs = validation ["quality_score" ]
139+ if isinstance (qs , dict ):
140+ quality = qs .get ("overall_score" , 0.0 )
141+
142+ # Check if validation contains a QualityScore object (after serialization)
143+ if quality == 0.0 :
144+ # Try to find any score field
145+ for key in ["overall_score" , "quality_score" , "score" ]:
146+ if key in validation :
147+ val = validation [key ]
148+ if isinstance (val , (int , float )) and val > 0 :
149+ quality = float (val )
150+ break
151+
152+ if quality > 0 :
153+ logger .debug (f"Extracted quality score from validation dict: { quality } for doc { _sanitize_log_data (doc_id )} " )
154+
155+ return quality
156+
157+ def _extract_quality_score_from_validation_object (
158+ self , validation : Any , doc_id : str
159+ ) -> float :
160+ """Extract quality score from validation object (with attributes)."""
161+ if hasattr (validation , "overall_score" ):
162+ quality = getattr (validation , "overall_score" , 0.0 )
163+ logger .debug (f"Extracted quality score from validation object: { quality } for doc { _sanitize_log_data (doc_id )} " )
164+ return quality
165+ elif hasattr (validation , "quality_score" ):
166+ quality = getattr (validation , "quality_score" , 0.0 )
167+ logger .debug (f"Extracted quality score from validation object (quality_score): { quality } for doc { _sanitize_log_data (doc_id )} " )
168+ return quality
169+ else :
170+ logger .debug (f"Validation result for doc { _sanitize_log_data (doc_id )} is not a dict or object with score attributes. Type: { type (validation )} " )
171+ return 0.0
172+
125173 def _create_quality_score_from_validation (
126174 self , validation_data : Union [Dict [str , Any ], Any ]
127175 ) -> Any :
@@ -1155,7 +1203,7 @@ def _get_mock_extraction_data(self) -> Dict[str, Any]:
11551203 # Generate line items
11561204 line_items = []
11571205 num_items = random .randint (2 , 8 )
1158- for i in range (num_items ):
1206+ for _ in range (num_items ):
11591207 item_names = ["Widget A" , "Component B" , "Part C" , "Module D" , "Assembly E" ]
11601208 item_name = random .choice (item_names )
11611209 quantity = random .randint (1 , 50 )
@@ -1365,41 +1413,9 @@ async def _get_analytics_data(
13651413
13661414 # Handle different validation result structures
13671415 if isinstance (validation , dict ):
1368- # Check for overall_score directly (this is the main field from JudgeEvaluation)
1369- quality = validation .get ("overall_score" , 0.0 )
1370-
1371- # If not found, check for quality_score field
1372- if quality == 0.0 :
1373- quality = validation .get ("quality_score" , 0.0 )
1374-
1375- # If still not found, check nested structures
1376- if quality == 0.0 and "quality_score" in validation :
1377- qs = validation ["quality_score" ]
1378- if isinstance (qs , dict ):
1379- quality = qs .get ("overall_score" , 0.0 )
1380-
1381- # Check if validation contains a QualityScore object (after serialization)
1382- if quality == 0.0 :
1383- # Try to find any score field
1384- for key in ["overall_score" , "quality_score" , "score" ]:
1385- if key in validation :
1386- val = validation [key ]
1387- if isinstance (val , (int , float )) and val > 0 :
1388- quality = float (val )
1389- break
1390-
1391- logger .debug (f"Extracted quality score from validation dict: { quality } for doc { _sanitize_log_data (doc_id )} " )
1392-
1393- elif hasattr (validation , "overall_score" ):
1394- # It's an object with overall_score attribute (JudgeEvaluation dataclass)
1395- quality = getattr (validation , "overall_score" , 0.0 )
1396- logger .debug (f"Extracted quality score from validation object: { quality } for doc { _sanitize_log_data (doc_id )} " )
1397- elif hasattr (validation , "quality_score" ):
1398- # It's an object with quality_score attribute
1399- quality = getattr (validation , "quality_score" , 0.0 )
1400- logger .debug (f"Extracted quality score from validation object (quality_score): { quality } for doc { _sanitize_log_data (doc_id )} " )
1416+ quality = self ._extract_quality_score_from_validation_dict (validation , doc_id )
14011417 else :
1402- logger . debug ( f"Validation result for doc { _sanitize_log_data ( doc_id ) } is not a dict or object with score attributes. Type: { type (validation ) } " )
1418+ quality = self . _extract_quality_score_from_validation_object (validation , doc_id )
14031419
14041420 # If still no quality score found, try to get it from extraction data
14051421 if quality == 0.0 :
0 commit comments