MCPcopy Create free account
hub / github.com/google/adk-samples / evaluate_case

Function evaluate_case

python/agents/invoice-processing/eval/eval.py:836–889  ·  view source on GitHub ↗

Evaluate a single case by comparing ground truth and agent output. When master data is provided, uses schema-driven comparison groups. Otherwise falls back to the hardcoded invoice-specific comparators.

(
    case_id: str,
    gt_file: Path,
    agent_file: Path,
    tolerance: float,
    llm_model: Any | None = None,
    master: MasterData | None = None,
)

Source from the content-addressed store, hash-verified

834
835
836def evaluate_case(
837 case_id: str,
838 gt_file: Path,
839 agent_file: Path,
840 tolerance: float,
841 llm_model: Any | None = None,
842 master: MasterData | None = None,
843) -> dict:
844 """Evaluate a single case by comparing ground truth and agent output.
845
846 When master data is provided, uses schema-driven comparison groups.
847 Otherwise falls back to the hardcoded invoice-specific comparators.
848 """
849
850 # Load files
851 try:
852 gt = json.loads(gt_file.read_text(encoding="utf-8"))
853 except Exception as e:
854 return {
855 "case_id": case_id,
856 "status": "ERROR",
857 "error": f"Failed to load ground truth: {e}",
858 }
859
860 try:
861 agent = json.loads(agent_file.read_text(encoding="utf-8"))
862 except Exception as e:
863 return {
864 "case_id": case_id,
865 "status": "ERROR",
866 "error": f"Failed to load agent output: {e}",
867 }
868
869 # Decision comparison (always schema-driven when master data available)
870 decision = compare_decision(gt, agent, master)
871
872 # Field group comparisons — schema-driven or legacy fallback
873 if master:
874 result_dict = _evaluate_schema_driven(
875 case_id, gt, agent, decision, master, tolerance
876 )
877 else:
878 result_dict = _evaluate_legacy(case_id, gt, agent, decision, tolerance)
879
880 # LLM alignment verdict (optional)
881 llm_verdict = None
882 if llm_model is not None:
883 domain_name = master.display_name if master else "invoice processing"
884 llm_verdict = llm_evaluate(
885 llm_model, gt, agent, result_dict["mismatches"], domain_name
886 )
887 result_dict["llm_verdict"] = llm_verdict
888
889 return result_dict
890
891
892# ============================================================================

Callers 1

_run_evaluation_loopFunction · 0.85

Calls 4

compare_decisionFunction · 0.85
_evaluate_schema_drivenFunction · 0.85
_evaluate_legacyFunction · 0.85
llm_evaluateFunction · 0.85

Tested by

no test coverage detected