Spaces:
Running
Running
Commit ·
4baabbe
1
Parent(s): a9424d2
fix: PG2 label check — model returns LABEL_0/LABEL_1, not MALICIOUS/BENIGN
Browse files
env/defenses/prompt_guard.py
CHANGED
|
@@ -65,11 +65,14 @@ class PromptGuard:
|
|
| 65 |
label: str = result["label"].upper()
|
| 66 |
score: float = float(result["score"])
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
|
|
|
|
| 71 |
return DefenseVerdict(
|
| 72 |
flagged=flagged,
|
| 73 |
score=pg2_score,
|
| 74 |
-
reason=f"pg2:{
|
| 75 |
)
|
|
|
|
| 65 |
label: str = result["label"].upper()
|
| 66 |
score: float = float(result["score"])
|
| 67 |
|
| 68 |
+
# PG2 returns LABEL_0 (benign) or LABEL_1 (injection).
|
| 69 |
+
# Some builds expose BENIGN/MALICIOUS — handle both.
|
| 70 |
+
flagged = label in ("LABEL_1", "MALICIOUS", "INJECTION")
|
| 71 |
+
pg2_score = score if flagged else 1.0 - score # probability of injection
|
| 72 |
|
| 73 |
+
label_str = "injection" if flagged else "benign"
|
| 74 |
return DefenseVerdict(
|
| 75 |
flagged=flagged,
|
| 76 |
score=pg2_score,
|
| 77 |
+
reason=f"pg2:{label_str}",
|
| 78 |
)
|