Skip to content

Commit 1e75082

Browse files
committed
🚧 added the new field in the response indicating clearly whether or not guardrail status is a success or failure
1 parent 5b340ef commit 1e75082

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

detectors/guardrails_ai_wrapper/detector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,19 @@ def run(self, input: ContentAnalysisHttpRequest) -> ContentsAnalysisResponse:
3535
try:
3636
logger.info(f"Validating text: {text}")
3737
validation_result = self.guard.validate(text)
38+
status = "success"
3839
logger.info(f"Validation successful for text: {text}")
3940
except Exception as e:
4041
logger.error(f"Validation failed for text: {text} with error: {e}")
4142
validation_result = str(e)
43+
status = "failed"
4244

4345
content_analyses.append(
4446
ContentAnalysisResponse(
47+
detection_type="guardrails_ai",
48+
status=status,
4549
start=0,
4650
end=len(text),
47-
detection_type="guardrails_ai",
4851
text=text,
4952
validation_result=validation_result,
5053
evidences=[],

detectors/guardrails_ai_wrapper/scheme.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ class ContentAnalysisHttpRequest(BaseModel):
3939

4040
class ContentAnalysisResponse(BaseModel):
4141
model_config = ConfigDict(arbitrary_types_allowed=True)
42+
detection_type: str = Field(example="detection_type")
43+
status: str = Field(
44+
example="success", description="Indicates whether validation passed or failed"
45+
)
4246
start: int = Field(example=14)
4347
end: int = Field(example=26)
44-
detection_type: str = Field(example="detection_type")
4548
text: str = Field(
4649
example="My email address is [email protected] and [email protected]"
4750
)

0 commit comments

Comments
 (0)