From 8ca7546a18eed2b89e90ef3c19ff8ec6c99342b6 Mon Sep 17 00:00:00 2001 From: Jan Tychtl Date: Wed, 25 Nov 2026 16:02:12 +0100 Subject: [PATCH] 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 --- .../core/evaluators/_deep_subset.py | 17 +++++++++++++-- .../gooddata-eval/tests/test_deep_subset.py | 21 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/gooddata-eval/src/gooddata_eval/core/evaluators/_deep_subset.py b/packages/gooddata-eval/src/gooddata_eval/core/evaluators/_deep_subset.py index 495b41d7c..a02c78f95 100644 --- a/packages/gooddata-eval/src/gooddata_eval/core/evaluators/_deep_subset.py +++ b/packages/gooddata-eval/src/gooddata_eval/core/evaluators/_deep_subset.py @@ -1,6 +1,7 @@ # (C) 2026 GoodData Corporation """Recursive subset matcher for alert filter comparison.""" +from decimal import Decimal, InvalidOperation from typing import Any @@ -12,7 +13,9 @@ def deep_subset(expected: Any, actual: Any) -> bool: claims the first unused actual element it deep-subset-matches. Sufficient for alert filters (small, distinct-type lists); may miss valid matchings when two expected items could match the same actual item. - - other: equality. + - other: equality. A number also matches a numeric string of the same value, + because the agent's tools accept both (`500` and `"500"` set the same threshold); + two strings, and booleans, still compare exactly. """ if isinstance(expected, dict): if not isinstance(actual, dict): @@ -32,4 +35,14 @@ def deep_subset(expected: Any, actual: Any) -> bool: if not matched: return False return True - return expected == actual + return expected == actual or _same_number(expected, actual) or _same_number(actual, expected) + + +def _same_number(input_a: Any, input_b: Any) -> bool: + if not isinstance(input_a, (int, float)) or isinstance(input_a, bool) or not isinstance(input_b, str): + return False + # Decimal, not float: float("9007199254740993") rounds to 9007199254740992. + try: + return Decimal(input_b) == Decimal(str(input_a)) + except InvalidOperation: + return False diff --git a/packages/gooddata-eval/tests/test_deep_subset.py b/packages/gooddata-eval/tests/test_deep_subset.py index ba32170fc..498b48ee2 100644 --- a/packages/gooddata-eval/tests/test_deep_subset.py +++ b/packages/gooddata-eval/tests/test_deep_subset.py @@ -1,4 +1,5 @@ # (C) 2026 GoodData Corporation +import pytest from gooddata_eval.core.evaluators._deep_subset import deep_subset @@ -32,3 +33,23 @@ def test_deep_subset_nested(): expected = {"filter": {"in": {"values": ["abc"]}}} actual = {"filter": {"in": {"values": ["abc"]}, "extra": True}} assert deep_subset(expected, actual) is True + + +@pytest.mark.parametrize( + ("expected", "actual", "matches"), + [ + pytest.param(500, "500", True, id="int-and-numeric-string"), + pytest.param(0.15, "0.15", True, id="float-and-numeric-string"), + pytest.param(500, "500.0", True, id="int-and-float-string"), + pytest.param("500", 500, True, id="numeric-string-and-int"), + pytest.param(9007199254740993, "9007199254740993", True, id="large-int-and-its-string"), + pytest.param({"threshold": 10000}, {"threshold": "10000", "operator": "LESS_THAN"}, True, id="tool-args"), + pytest.param(500, "501", False, id="different-value"), + pytest.param(9007199254740992, "9007199254740993", False, id="large-int-off-by-one"), + pytest.param(500, "five hundred", False, id="non-numeric-string"), + pytest.param("500", "500.0", False, id="two-strings-stay-exact"), + pytest.param(True, "1", False, id="bool-is-not-a-number"), + ], +) +def test_deep_subset_number_matches_numeric_string(expected, actual, matches): + assert deep_subset(expected, actual) is matches