@@ -600,6 +600,88 @@ async def get_knowledge_gaps_from_failures(days: int = 7):
600600 logger .error (f"Knowledge gaps analysis error: { e } " )
601601 return {"knowledge_gaps" : [], "error" : str (e )}
602602
603+ @router .get ("/api/validators/performance" )
604+ async def get_validator_performance_dashboard (days : int = 7 ):
605+ """
606+ Get Validator Performance Dashboard (Gemini's recommendation).
607+
608+ This endpoint provides per-validator performance statistics including:
609+ - Total checks, pass/fail counts, pass rates
610+ - Failure detection rate (how often validators catch issues)
611+ - Average execution time (if tracked)
612+ - Common failure reasons per validator
613+
614+ This helps identify:
615+ - Validators that rarely catch issues (candidates for consolidation)
616+ - Validators with high false positive rates
617+ - Performance bottlenecks (slow validators)
618+
619+ Args:
620+ days: Number of days to analyze (default: 7)
621+
622+ Returns:
623+ Dictionary mapping validator_name to performance stats:
624+ {
625+ "CitationRequired": {
626+ "total_checks": 100,
627+ "passed": 95,
628+ "failed": 5,
629+ "pass_rate": 0.95,
630+ "failure_detection_rate": 0.05,
631+ "avg_execution_time": 0.012,
632+ "common_failure_reasons": {"missing_citation": 5}
633+ },
634+ ...
635+ }
636+ """
637+ try :
638+ from backend .validators .validation_metrics_tracker import get_validation_tracker
639+ tracker = get_validation_tracker ()
640+ stats = tracker .get_validator_performance_stats (days = days )
641+
642+ # Calculate summary statistics
643+ total_validators = len (stats )
644+ total_checks = sum (s .get ("total_checks" , 0 ) for s in stats .values ())
645+
646+ # Identify validators with low failure detection (candidates for consolidation)
647+ low_detection_validators = [
648+ name for name , s in stats .items ()
649+ if s .get ("total_checks" , 0 ) > 10 and s .get ("failure_detection_rate" , 0 ) < 0.01
650+ ]
651+
652+ # Identify slow validators (if execution time tracked)
653+ slow_validators = [
654+ {
655+ "name" : name ,
656+ "avg_execution_time" : s .get ("avg_execution_time" , 0 )
657+ }
658+ for name , s in stats .items ()
659+ if s .get ("avg_execution_time" ) and s .get ("avg_execution_time" , 0 ) > 0.1
660+ ]
661+ slow_validators .sort (key = lambda x : x ["avg_execution_time" ], reverse = True )
662+
663+ return {
664+ "status" : "success" ,
665+ "analysis_period_days" : days ,
666+ "summary" : {
667+ "total_validators" : total_validators ,
668+ "total_checks" : total_checks ,
669+ "validators_with_low_detection" : low_detection_validators ,
670+ "slow_validators" : slow_validators [:5 ] # Top 5 slowest
671+ },
672+ "validators" : stats ,
673+ "timestamp" : datetime .now ().isoformat ()
674+ }
675+ except Exception as e :
676+ logger .error (f"Validator performance dashboard error: { e } " , exc_info = True )
677+ return {
678+ "status" : "error" ,
679+ "error" : str (e ),
680+ "analysis_period_days" : days ,
681+ "validators" : {},
682+ "timestamp" : datetime .now ().isoformat ()
683+ }
684+
603685@router .get ("/api/cache/stats" )
604686async def get_cache_stats ():
605687 """Get cache statistics"""
0 commit comments