mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
fix compliance checks for array guardrail modes
Treat guardrail_mode arrays like [\"pre_call\", \"post_call\"] as valid pre-call executions so EU AI Act and GDPR checks stop reporting false non-compliance. Add regression tests to cover both EU and GDPR paths. Made-with: Cursor
This commit is contained in:
parent
672f939631
commit
e3e4956050
2 changed files with 44 additions and 0 deletions
|
|
@ -41,6 +41,8 @@ class ComplianceChecker:
|
|||
# If no mode specified, default to pre_call
|
||||
if g_mode is None and mode == "pre_call":
|
||||
result.append(g)
|
||||
elif isinstance(g_mode, list) and mode in g_mode:
|
||||
result.append(g)
|
||||
elif g_mode == mode:
|
||||
result.append(g)
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -310,6 +310,27 @@ class TestEuAiActCompliant:
|
|||
checks = ComplianceChecker(data).check_eu_ai_act()
|
||||
assert all(c.passed for c in checks)
|
||||
|
||||
def test_pre_call_detected_when_mode_is_array(self):
|
||||
"""Array guardrail_mode should count toward pre-call screening."""
|
||||
data = ComplianceCheckRequest(
|
||||
request_id="req-203",
|
||||
user_id="user-2",
|
||||
model="gpt-4o-mini",
|
||||
timestamp="2026-02-17T12:00:00Z",
|
||||
guardrail_information=[
|
||||
{
|
||||
"guardrail_name": "presidio-output-parse",
|
||||
"guardrail_mode": ["pre_call", "post_call"],
|
||||
"guardrail_status": "success",
|
||||
}
|
||||
],
|
||||
)
|
||||
checks = ComplianceChecker(data).check_eu_ai_act()
|
||||
results = {c.check_name: c.passed for c in checks}
|
||||
assert results["Guardrails applied"] is True
|
||||
assert results["Content screened before LLM"] is True
|
||||
assert results["Audit record complete"] is True
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# GDPR — Compliant cases (Task #4)
|
||||
|
|
@ -385,3 +406,24 @@ class TestGdprCompliant:
|
|||
)
|
||||
checks = ComplianceChecker(data).check_gdpr()
|
||||
assert all(c.passed for c in checks)
|
||||
|
||||
def test_gdpr_pre_call_detected_when_mode_is_array(self):
|
||||
"""Array guardrail_mode should satisfy GDPR pre-call data protection checks."""
|
||||
data = ComplianceCheckRequest(
|
||||
request_id="req-304",
|
||||
user_id="user-2",
|
||||
model="gpt-4o-mini",
|
||||
timestamp="2026-02-17T12:00:00Z",
|
||||
guardrail_information=[
|
||||
{
|
||||
"guardrail_name": "presidio-output-parse",
|
||||
"guardrail_mode": ["pre_call", "post_call"],
|
||||
"guardrail_status": "success",
|
||||
}
|
||||
],
|
||||
)
|
||||
checks = ComplianceChecker(data).check_gdpr()
|
||||
results = {c.check_name: c.passed for c in checks}
|
||||
assert results["Data protection applied"] is True
|
||||
assert results["Sensitive data protected"] is True
|
||||
assert results["Audit record complete"] is True
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue