Generic field group comparison driven by eval_schema.comparison_groups. This is the schema-driven replacement for compare_financials, compare_vendor, and compare_header. Each group config specifies the section name and a list of fields with their comparison type ("amount" or "string
(
gt: dict, agent: dict, group_config: dict, tolerance: float
)
| 306 | |
| 307 | |
| 308 | def compare_field_group( |
| 309 | gt: dict, agent: dict, group_config: dict, tolerance: float |
| 310 | ) -> dict: |
| 311 | """Generic field group comparison driven by eval_schema.comparison_groups. |
| 312 | |
| 313 | This is the schema-driven replacement for compare_financials, compare_vendor, |
| 314 | and compare_header. Each group config specifies the section name and a list of |
| 315 | fields with their comparison type ("amount" or "string"). |
| 316 | """ |
| 317 | section = group_config.get("section", "") |
| 318 | gt_section = gt.get(section) or {} |
| 319 | agent_section = agent.get(section) or {} |
| 320 | |
| 321 | results = {} |
| 322 | all_match = True |
| 323 | |
| 324 | for field in group_config.get("fields", []): |
| 325 | field_name = field["name"] |
| 326 | field_type = field.get("type", "string") |
| 327 | |
| 328 | gt_val = str(gt_section.get(field_name, "")).strip() |
| 329 | agent_val = str(agent_section.get(field_name, "")).strip() |
| 330 | |
| 331 | if field_type == "amount": |
| 332 | match = amounts_match(gt_val, agent_val, tolerance) |
| 333 | else: |
| 334 | match = normalize_string(gt_val) == normalize_string(agent_val) |
| 335 | |
| 336 | if not match: |
| 337 | all_match = False |
| 338 | |
| 339 | results[field_name] = { |
| 340 | "ground_truth": gt_val, |
| 341 | "agent": agent_val, |
| 342 | "match": match, |
| 343 | } |
| 344 | |
| 345 | results["all_match"] = all_match |
| 346 | return results |
| 347 | |
| 348 | |
| 349 | def _compare_per_line_fields( |
no test coverage detected