Skip to content

Commit bd23984

Browse files
authored
Content safety evaluation won't fail on empty content (#532)
1 parent 6548e12 commit bd23984

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • libraries/python/content-safety/content_safety/evaluators/azure_content_safety

libraries/python/content-safety/content_safety/evaluators/azure_content_safety/evaluator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,21 @@ async def _evaluate_batch(self, text: str) -> ContentSafetyEvaluation:
100100
Evaluate a batch of content for safety using the Azure Content Safety service.
101101
"""
102102

103+
if not text.strip():
104+
# if the text is empty, return a pass result
105+
return ContentSafetyEvaluation(
106+
result=ContentSafetyEvaluationResult.Pass,
107+
note="Empty content.",
108+
)
109+
103110
# send the text to the Azure Content Safety service for evaluation
104111
try:
105112
response = ContentSafetyClient(
106113
endpoint=str(self.config.azure_content_safety_endpoint),
107114
credential=self.config._get_azure_credentials(),
108115
).analyze_text(AnalyzeTextOptions(text=text))
109116
except Exception as e:
117+
logger.exception("azure content safety check failed")
110118
# if there is an error, return a fail result with the error message
111119
return ContentSafetyEvaluation(
112120
result=ContentSafetyEvaluationResult.Fail,

0 commit comments

Comments
 (0)