Skip to content

Fix Expense scoring: amount_dollars trailing zeros and substring-friendly fuzzy_match - #394

Open
jackliuw1983-afk wants to merge 3 commits into
google-research:mainfrom
jackliuw1983-afk:fix-expense-amount-dollar-format
Open

jackliuw1983-afk wants to merge 3 commits into
google-research:mainfrom
jackliuw1983-afk:fix-expense-amount-dollar-format

Conversation

@jackliuw1983-afk

@jackliuw1983-afk jackliuw1983-afk commented Nov 6, 2026 •

Copy link
Copy Markdown

Problem

Two scoring bugs cause ExpenseAddMultipleFromMarkor (and related expense tasks) to produce false negatives.

1. Expense.amount_dollars drops trailing zeros

Expense.amount_dollars formats the amount with a bare f-string float division:

return f'${self.amount / 100}'

This drops trailing zeros, so an amount of 9630 cents renders as $96.3 instead of $96.30. The verifier (validate_rows_addition_integrity) requires an exact match on the integer-cent amount field — only name/note are fuzzy-matched — so a value like $96.3 is ambiguous and can mislead the agent into storing 9603 rather than 9630 cents.

2. fuzzy_match is length-sensitive, breaking note matches with a marker suffix

ExpenseAddMultipleFromMarkor appends a . Reimbursable. marker to the target rows' notes in the source file:

targets = [
    dataclasses.replace(row, note=row.note + '. ' + 'Reimbursable.')
    for row in self.params[sqlite_validators.ROW_OBJECTS]
]

The agent transcribes the note verbatim (e.g. Urgent. Reimbursable.) into the app, but the verifier fuzzy-matches it against the original note (Urgent). fuzzy_match used difflib.SequenceMatcher.ratio(), which is sensitive to length differences, so a clean prefix (Urgent vs Urgent. Reimbursable.) scores only 0.44 — below the 0.9 threshold — producing a false negative.

Fix

  1. Always render two decimals:
return f'${self.amount / 100:.2f}'
  1. Score with the best of full-string ratio and substring partial_ratio:
return max(fuzz.ratio(text1, text2), fuzz.partial_ratio(text1, text2)) >= _MIN_DIFF_SIMILARITY * 100

partial_ratio returns 100 for Urgent vs Urgent. Reimbursable.. Taking the max keeps those substring matches while not regressing mid-string insertions (Elm St vs Elm Street, which partial_ratio alone would undershoot).

@google-cla

google-cla Bot commented Nov 6, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

f"{self.amount / 100}" drops trailing zeros, e.g. 9630 cents renders as "$96.3" instead of "$96.30". Agents that transcribe this ambiguous amount back into the expense app can then fail the exact integer-cent comparison in validate_rows_addition_integrity. Format with two decimals.
@jackliuw1983-afk
jackliuw1983-afk force-pushed the fix-expense-amount-dollar-format branch from 466509b to 39412e0 Compare November 6, 2026 12:52
Score with the best of full-string ratio and substring partial_ratio. ratio alone is length-sensitive, so a value carrying a short suffix/prefix (e.g. "Urgent" vs "Urgent. Reimbursable.") fell below the 0.9 threshold (0.44) even though the core text is a substring; partial_ratio returns 100 there. Taking the max keeps those substring matches without regressing mid-string insertions ("Elm St" vs "Elm Street").
@jackliuw1983-afk jackliuw1983-afk changed the title Fix Expense.amount_dollars to always render two decimals Fix Expense scoring: amount_dollars trailing zeros and substring-friendly fuzzy_match Nov 7, 2026
Comment thread android_world/utils/fuzzy_match_lib.py Resolved
… note

fuzzy_match is a shared helper used for contact names, SMS bodies, file
contents, playlist names, and free-form DB fields. It was changed to
max(ratio, partial_ratio), which scores any substring as a match (e.g.
fuzzy_match('Joanne', 'Ann') now returns True). Revert fuzzy_match to
fuzz.ratio only, and add fuzzy_match_substring (max of ratio and
partial_ratio) scoped solely to the expense note free-form field, where the
candidate legitimately appends the ". Reimbursable." marker.

Restore empty == empty matching: the original difflib implementation scored
SequenceMatcher(None, '', '').ratio() == 1.0, but the thefuzz port's
`if not text1 or not text2: return False` regressed it. Empty free-form
fields (recipe source, calendar location) now match again.

Adds fuzzy_match_lib_test.py with a regression covering the substring false
positives.

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

Development

Successfully merging this pull request may close these issues.

2 participants