Skip to content

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

Open
Vijaysrimari wants to merge 9 commits into
ServiceNow:mainfrom
Vijaysrimari:fix/assistantbench-thousands-comma-scorer-404
Open

Vijaysrimari wants to merge 9 commits into
ServiceNow:mainfrom
Vijaysrimari:fix/assistantbench-thousands-comma-scorer-404

Conversation

@Vijaysrimari

Copy link
Copy Markdown

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

…imal commas in fix_number

Closes ServiceNow#404

The old code called .replace(',', '.') unconditionally in fix_number(),
causing two classes of silent scoring errors:
- '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

Fix: extract disambiguation logic into _fix_comma() in evaluate_utils/utils.py
and call it from both fix_number() implementations (evaluator.py and
evaluate_dicts.py).

Disambiguation rules:
- Multiple commas         -> US grouping, strip all  ('3,080,000' -> '3080000')
- Single comma + 3 digits -> thousands separator     ('1,000'     -> '1000')
- Single comma + 1-2 digs -> European decimal comma  ('14,2'      -> '14.2')
- Anything else           -> leave unchanged (falls back to string comparison)

Also narrows bare except: clauses to explicit exception types.

Tests added (23 new cases):
- test_fix_comma              - 12-case parametrized unit test for _fix_comma
- test_evaluate_comma_numbers - 9-case end-to-end question_scorer test
- test_evaluate_comma_numbers_in_dicts - dict evaluation path
- test_evaluate_comma_numbers_negative - negative thousands separator
@Vijaysrimari

Copy link
Copy Markdown
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!

…imal commas in fix_number

Closes ServiceNow#404

The old code called .replace(',', '.') unconditionally in fix_number(),
causing two classes of silent scoring errors:
- '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

Fix: extract disambiguation logic into _fix_comma() in evaluate_utils/utils.py
and call it from both fix_number() implementations (evaluator.py and
evaluate_dicts.py).

Disambiguation rules:
- Multiple commas         -> US grouping, strip all  ('3,080,000' -> '3080000')
- Single comma + 3 digits -> thousands separator     ('1,000'     -> '1000')
- Single comma + 1-2 digs -> European decimal comma  ('14,2'      -> '14.2')
- Anything else           -> leave unchanged (falls back to string comparison)

Also narrows bare except: clauses to explicit exception types.

Tests added (23 new cases):
- test_fix_comma              - 12-case parametrized unit test for _fix_comma
- test_evaluate_comma_numbers - 9-case end-to-end question_scorer test
- test_evaluate_comma_numbers_in_dicts - dict evaluation path
- test_evaluate_comma_numbers_negative - negative thousands separator
@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!

Vijaysrimari and others added 5 commits October 28, 2026 22:58
Update regex from (-?\d+),(\d+) to (-?\d+),(\d+)(\.\d+)? so that
strings like '1,000.50' and '1,234.56' are correctly recognised as
thousands-separator notation and have the comma stripped, yielding
'1000.50' and '1234.56' respectively.

Add test cases for this edge case in test_fix_comma and
test_evaluate_comma_numbers.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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