Skip to content

Commit 8ca7546

Browse files
committed
fix(gooddata-eval): match a number to a numeric string in tool args
The agent's alert tools accept a threshold as a number or as a numeric string, and both create the same alert. Some models' tool-call parsers return the string form for a parameter typed number-or-string, so a call with threshold "500" failed an item that expects 500 although the alert the agent created was correct. deep_subset now treats a number and a numeric string as equal when their values are equal, compared as Decimal so large integers keep their precision. Two strings, and booleans, still compare exactly. The alert-skill checks already compare thresholds by value (_to_number); this brings the conversation tool-argument check in line with them. jira: GDAI-2890 risk: low
1 parent 99b56b2 commit 8ca7546

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

‎packages/gooddata-eval/src/gooddata_eval/core/evaluators/_deep_subset.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# (C) 2026 GoodData Corporation
22
"""Recursive subset matcher for alert filter comparison."""
33

4+
from decimal import Decimal, InvalidOperation
45
from typing import Any
56

67

@@ -12,7 +13,9 @@ def deep_subset(expected: Any, actual: Any) -> bool:
1213
claims the first unused actual element it deep-subset-matches. Sufficient
1314
for alert filters (small, distinct-type lists); may miss valid matchings
1415
when two expected items could match the same actual item.
15-
- other: equality.
16+
- other: equality. A number also matches a numeric string of the same value,
17+
because the agent's tools accept both (`500` and `"500"` set the same threshold);
18+
two strings, and booleans, still compare exactly.
1619
"""
1720
if isinstance(expected, dict):
1821
if not isinstance(actual, dict):
@@ -32,4 +35,14 @@ def deep_subset(expected: Any, actual: Any) -> bool:
3235
if not matched:
3336
return False
3437
return True
35-
return expected == actual
38+
return expected == actual or _same_number(expected, actual) or _same_number(actual, expected)
39+
40+
41+
def _same_number(input_a: Any, input_b: Any) -> bool:
42+
if not isinstance(input_a, (int, float)) or isinstance(input_a, bool) or not isinstance(input_b, str):
43+
return False
44+
# Decimal, not float: float("9007199254740993") rounds to 9007199254740992.
45+
try:
46+
return Decimal(input_b) == Decimal(str(input_a))
47+
except InvalidOperation:
48+
return False

‎packages/gooddata-eval/tests/test_deep_subset.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# (C) 2026 GoodData Corporation
2+
import pytest
23
from gooddata_eval.core.evaluators._deep_subset import deep_subset
34

45

@@ -32,3 +33,23 @@ def test_deep_subset_nested():
3233
expected = {"filter": {"in": {"values": ["abc"]}}}
3334
actual = {"filter": {"in": {"values": ["abc"]}, "extra": True}}
3435
assert deep_subset(expected, actual) is True
36+
37+
38+
@pytest.mark.parametrize(
39+
("expected", "actual", "matches"),
40+
[
41+
pytest.param(500, "500", True, id="int-and-numeric-string"),
42+
pytest.param(0.15, "0.15", True, id="float-and-numeric-string"),
43+
pytest.param(500, "500.0", True, id="int-and-float-string"),
44+
pytest.param("500", 500, True, id="numeric-string-and-int"),
45+
pytest.param(9007199254740993, "9007199254740993", True, id="large-int-and-its-string"),
46+
pytest.param({"threshold": 10000}, {"threshold": "10000", "operator": "LESS_THAN"}, True, id="tool-args"),
47+
pytest.param(500, "501", False, id="different-value"),
48+
pytest.param(9007199254740992, "9007199254740993", False, id="large-int-off-by-one"),
49+
pytest.param(500, "five hundred", False, id="non-numeric-string"),
50+
pytest.param("500", "500.0", False, id="two-strings-stay-exact"),
51+
pytest.param(True, "1", False, id="bool-is-not-a-number"),
52+
],
53+
)
54+
def test_deep_subset_number_matches_numeric_string(expected, actual, matches):
55+
assert deep_subset(expected, actual) is matches

0 commit comments

Comments
 (0)