Skip to content

fix(assistantbench): disambiguate thousands-separator commas from decimal commas in fix_number - #414

Merged
Surya-5555 merged 1 commit into
ServiceNow:mainfrom
Vijaysrimari:fix/assistantbench-thousands-comma-scorer-404
Nov 17, 2026
Merged

Surya-5555 merged 1 commit into
ServiceNow:mainfrom
Vijaysrimari:fix/assistantbench-thousands-comma-scorer-404

Conversation

@Vijaysrimari

Copy link
Copy Markdown
Contributor

PR Description

Closes #404


What changed and why

fix_number() in both evaluator.py and evaluate_dicts.py previously called .replace(",", ".") unconditionally, which silently corrupted scores in two directions:

  • "3,080,000" → "3.080.000" → float() raises → correct answer scores 0.0
  • "1,000" → "1.000" = 1.0 → matched gold 1 → wrong answer scores 1.0

The fix extracts the disambiguation logic into a single helper _fix_comma(number: str) -> str in the shared evaluate_utils/utils.py, then calls it from both fix_number() implementations.

Disambiguation rules (in priority order):

Input Rule Output
"3,080,000" Multiple commas → US grouping, strip all "3080000"
"1,000" Single comma + exactly 3 digits → thousands separator, strip "1000"
"14,2" Single comma + 1–2 digits → European decimal comma, replace "14.2"
"1,0000" Single comma + 4+ digits → ambiguous, leave unchanged "1,0000"
"hello" No comma → pass through unchanged "hello"

Files changed

File Change
evaluate_utils/utils.py Added _fix_comma() with full docstring — single source of truth
evaluator.py Removed buggy .replace(",","."), imported and called _fix_comma; also narrowed bare except: to except (ValueError, TypeError)
evaluate_utils/evaluate_dicts.py Same fix applied to the dict-path fix_number()
tests/assistantbench/test_evaluation.py Added 23 new test cases across 4 test functions

Proof of work

WhatsApp Image 2026-10-26 at 12 04 49 AM

@Vijaysrimari

Copy link
Copy Markdown
Contributor Author

Hi @Surya-5555,

I've raised this PR to fix #404: AssistantBench's fix_number() was treating thousands-separator commas as decimals ("3,080,000" scored 0, "1,000" wrongly matched 1). I added a shared _fix_comma() helper to handle both cases, plus 23 new tests.

Could you please review it and approve the pending workflow run? Thank you, and have a great day!

@Surya-5555

Copy link
Copy Markdown
Collaborator

Hi @Vijaysrimari, thanks for the PR and for the clear description!

The Unit tests / code-format check is currently failing. Could you please look into it and fix the formatting for the files you changed only (utils.py, evaluator.py, evaluate_dicts.py and test_evaluation.py)? Please don't reformat unrelated files or code, so the diff stays focused on your change.

You can run the repo's formatter (see the code-format job / .pre-commit-config.yaml for the exact tool and settings) on just those files, commit, and push. The checks will re-run automatically.

Once that's green, I'll review it. Thanks!

@Surya-5555
Surya-5555 force-pushed the fix/assistantbench-thousands-comma-scorer-404 branch from afae07b to ccd59ee Compare October 28, 2026 16:33
@Surya-5555

Copy link
Copy Markdown
Collaborator

Hi @Vijaysrimari, thanks for the clean PR and great tests!

One edge case remains before merging: _fix_comma() currently fails on single-comma numbers with decimals (like "1,000.50" or "1,234.56"). The regex expects only digits after the comma, so the decimal dot causes the match to fail, returning the comma untouched and scoring 0.0 in float(). Multi-comma numbers like "3,080,000.50" work, but single-comma ones do not.

Approach to fix:
Please update the regex in _fix_comma() to allow an optional decimal dot and trailing digits, strip the comma when followed by 3 digits (even with a decimal part), and add a test case like "1,000.50".

Once that's added, happy to merge!

@Surya-5555

Copy link
Copy Markdown
Collaborator

Hi @Vijaysrimari, thank you for working on this! The PR cleanly resolves #404 across both the scalar and dictionary evaluation paths, and the test suite additions are very thorough.

Before merging, there are a few minor improvements to address:

  1. Multi-comma validation in _fix_comma (utils.py:56):
    Currently, if number.count(",") > 1: unconditionally strips all commas without checking if the string is actually a formatted number. For strings like "1,2,3", this collapses them into "123" (parsed as 123.0). Could you validate the structure (e.g. using re.fullmatch(r"-?\d{1,3}(,\d{2,3})+(\.\d+)?", number)) before stripping?

  2. Decimal handling with leading zero (utils.py:60):
    For numbers like "0,125", decimal_digits is 3, which causes it to be treated as a thousands separator and parsed as 125.0 instead of 0.125. If the integer part is "0" or "-0", it should always be treated as a decimal comma.

  3. Narrow except: in evaluate_dicts.py:49:
    In evaluator.py:68 you nicely narrowed the bare except: to except (ValueError, TypeError):. Please apply the same to line 49 in evaluate_dicts.py.

  4. Module docstring in test_evaluation.py:1:
    The module docstring currently reads """Tests for AssistantBench evaluation utilities (issue #404: comma disambiguation).""". Since this file covers general AssistantBench evaluation, please keep the module docstring generic ("""Tests for AssistantBench evaluation utilities.""") and leave the issue AssistantBench scorer treats a thousands separator as a decimal point: "3,080,000" scores 0 against gold 3080000, while "1,000" scores 1.0 against gold 1 #404 reference in the section comment on line 59.

  5. Commit history:
    The branch currently has 10 commits (including merge commits and formatting commits). Please squash your commits into a clean, single commit with a descriptive message before we merge.

Thanks again for the great contribution!

Validate grouped comma formats, preserve malformed values, and treat zero-leading comma values as decimals. Narrow numeric conversion handling and keep evaluation tests generic.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Vijaysrimari
Vijaysrimari force-pushed the fix/assistantbench-thousands-comma-scorer-404 branch from 4d0e580 to 20fb74c Compare November 17, 2026 09:51

@Surya-5555 Surya-5555 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Vijaysrimari, thanks for addressing all the feedback so quickly and thoroughly

The regex validation for grouped commas, leading-zero decimal comma handling, exception narrowing in evaluate_dicts.py, and the clean single squashed commit look great. All test additions pass cleanly

LGTM! Approving for merge

@Surya-5555
Surya-5555 merged commit e6e4e31 into ServiceNow:main Nov 17, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants