diff --git a/src/lighteval/metrics/normalizations.py b/src/lighteval/metrics/normalizations.py index 11c475ecc..49ea9216e 100644 --- a/src/lighteval/metrics/normalizations.py +++ b/src/lighteval/metrics/normalizations.py @@ -98,17 +98,20 @@ def _remove_boxed(text: str | None) -> str: """ if text is None: return "" - if "\\boxed " in text: - left = "\\boxed " - assert text[: len(left)] == left - return text[len(left) :] + try: + if "\\boxed " in text: + left = "\\boxed " + assert text[: len(left)] == left + return text[len(left) :] - left = "\\boxed{" + left = "\\boxed{" - assert text[: len(left)] == left - assert text[-1] == "}" + assert text[: len(left)] == left + assert text[-1] == "}" - return text[len(left) : -1] + return text[len(left) : -1] + except Exception: + return "" def _last_boxed_only_string(text: str) -> str | None: """Extract the last \\boxed{...} or \\fbox{...} element from a string."""