Repository navigation
Fix Expense scoring: amount_dollars trailing zeros and substring-friendly fuzzy_match - #394
Open
jackliuw1983-afk wants to merge 3 commits into
Open
jackliuw1983-afk wants to merge 3 commits into
jackliuw1983-afk wants to merge 3 commits into
Conversation
|
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
force-pushed
the
fix-expense-amount-dollar-format
branch
from
November 6, 2026 12:52
466509b to
39412e0
Compare
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").
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two scoring bugs cause
ExpenseAddMultipleFromMarkor(and related expense tasks) to produce false negatives.1.
Expense.amount_dollarsdrops trailing zerosExpense.amount_dollarsformats the amount with a bare f-string float division:This drops trailing zeros, so an amount of 9630 cents renders as
$96.3instead of$96.30. The verifier (validate_rows_addition_integrity) requires an exact match on the integer-centamountfield — onlyname/noteare fuzzy-matched — so a value like$96.3is ambiguous and can mislead the agent into storing 9603 rather than 9630 cents.2.
fuzzy_matchis length-sensitive, breaking note matches with a marker suffixExpenseAddMultipleFromMarkorappends a. Reimbursable.marker to the target rows' notes in the source file: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_matchuseddifflib.SequenceMatcher.ratio(), which is sensitive to length differences, so a clean prefix (UrgentvsUrgent. Reimbursable.) scores only 0.44 — below the 0.9 threshold — producing a false negative.Fix
ratioand substringpartial_ratio:partial_ratioreturns 100 forUrgentvsUrgent. Reimbursable.. Taking the max keeps those substring matches while not regressing mid-string insertions (Elm StvsElm Street, whichpartial_ratioalone would undershoot).