From 58efa3073f42afccd6d7d0907d0659642e14ecf8 Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Tue, 29 Sep 2026 11:50:07 +0000 Subject: [PATCH] fix(eval): raise the Invalid filter error for filters without an equals sign --- py/src/braintrust/framework.py | 2 +- py/src/braintrust/test_framework.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/py/src/braintrust/framework.py b/py/src/braintrust/framework.py index 471a2e379..b352252e9 100644 --- a/py/src/braintrust/framework.py +++ b/py/src/braintrust/framework.py @@ -1157,7 +1157,7 @@ def deserialize_plain_string_as_json(s: str) -> Any: def parse_filters(filters: list[str]) -> list[Filter]: result = [] for f in filters: - equals_idx = f.index("=") + equals_idx = f.find("=") if equals_idx == -1: raise ValueError(f"Invalid filter {f}") path, value = f[:equals_idx], f[equals_idx + 1 :] diff --git a/py/src/braintrust/test_framework.py b/py/src/braintrust/test_framework.py index 9dac69520..3e9dfe70b 100644 --- a/py/src/braintrust/test_framework.py +++ b/py/src/braintrust/test_framework.py @@ -1462,6 +1462,15 @@ def test_evaluate_filter_nested_metadata(self): f = Filter(path=["metadata", "priority"], pattern=re.compile("^P0$")) assert evaluate_filter(datum, f) is True + def test_parse_filters_splits_on_first_equals(self): + filters = parse_filters(["metadata.name=a=b"]) + assert filters[0].path == ["metadata", "name"] + assert filters[0].pattern.pattern == "a=b" + + def test_parse_filters_rejects_filter_without_equals(self): + with pytest.raises(ValueError, match="Invalid filter metadata.name"): + parse_filters(["metadata.name"]) + def test_evaluate_filter_input_field(self): datum = EvalCase(input={"text": "hello world"}, metadata={"name": "foo"}) f = Filter(path=["input", "text"], pattern=re.compile("hello"))