fix(sdk): add None input validation to heuristic metrics#6543
Open
zhoufengen wants to merge 4 commits intocomet-ml:mainfrom
Open
fix(sdk): add None input validation to heuristic metrics#6543zhoufengen wants to merge 4 commits intocomet-ml:mainfrom
zhoufengen wants to merge 4 commits intocomet-ml:mainfrom
Conversation
LevenshteinRatio.score() crashed with an unhelpful AttributeError when output or reference was None. Add explicit validation that raises MetricComputationError with a clear message, consistent with how other metrics like Sentiment and BLEU handle invalid inputs.
Equals.score() silently converted None to the string "None" via str(), producing misleading comparison results. Add explicit validation that raises MetricComputationError with a clear message.
RegexMatch.score() crashed with TypeError when output was None. Add explicit validation that raises MetricComputationError with a clear message.
alexkuzmik
reviewed
Apr 29, 2026
Collaborator
alexkuzmik
left a comment
There was a problem hiding this comment.
Thanks for the contribution. Could you please attach the unit test outputs?
Add tests verifying that Equals, LevenshteinRatio, and RegexMatch raise MetricComputationError when given None inputs, covering the validation logic added in this PR. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Several heuristic metrics (
LevenshteinRatio,Equals,RegexMatch) crash with unhelpful errors whenoutputorreferenceisNone. This commonly happens when LLM calls fail during evaluation and returnNonefor the output field.Changes
Nonecheck foroutputandreferencebefore calling.lower(), raisingMetricComputationErrorwith a descriptive messageNonecheck foroutputandreferencebeforestr()conversion (previouslyNonewas silently converted to the string"None", producing misleading results)Nonecheck foroutputbefore regex search, raisingMetricComputationErrorAll three now follow the same pattern used by existing metrics like
Sentiment,ROUGE, andBLEUthat already validate their inputs.Testing
MetricComputationError(fromopik.exceptions), which is the standard exception type used across the metrics moduleNoneinputs now produce a clear error message instead ofAttributeError: 'NoneType' object has no attribute 'lower'Related Issues
None (discovered during code review)