bedrock api response null type handling#25810
bedrock api response null type handling#25810ishaan-berri merged 4 commits intolitellm_ishaan_april15from
Conversation
|
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes a Confidence Score: 5/5Safe to merge — the fix is correct, targeted, and fully covered by new unit tests. All findings are P2 style suggestions. The core null-safety change is correct: No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py | Correct null-safety fix: replaces .get("key", []) with .get("key") or [] on all iterable list fields across _redact_pii_matches, _should_raise_guardrail_blocked_exception, and apply_guardrail to handle Bedrock's explicit null responses. |
| tests/test_litellm/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py | Three new test classes cover null-safety thoroughly: TestRedactPiiMatchesNullSafety, TestShouldRaiseGuardrailBlockedExceptionNullSafety, and TestApplyGuardrailNullSafety; all use mocks correctly and live in the unit-test folder. |
| tests/guardrails_tests/test_bedrock_guardrails.py | Three new standalone async test functions added; they only call synchronous helpers so the async def decoration is unnecessary overhead, but harmless. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Bedrock API response] --> B{assessments is null?}
B -->|null - explicit None| C[or-fallback returns empty list]
B -->|present| D[iterate assessments]
C --> E[return / no-op safely]
D --> F{sensitiveInformationPolicy present?}
D --> G{topicPolicy present?}
D --> H{contentPolicy present?}
D --> I{wordPolicy present?}
D --> J{contextualGroundingPolicy present?}
F -->|yes| F1[piiEntities or-fallback / regexes or-fallback]
G -->|yes| G1[topics or-fallback]
H -->|yes| H1[filters or-fallback]
I -->|yes| I1[customWords or-fallback / managedWordLists or-fallback]
J -->|yes| J1[filters or-fallback]
F1 --> K[safe iteration - no TypeError]
G1 --> K
H1 --> K
I1 --> K
J1 --> K
Comments Outside Diff (1)
-
tests/guardrails_tests/test_bedrock_guardrails.py, line 151-152 (link)Unnecessary
async defon sync-only testsThese three new test functions (
test__redact_pii_matches_null_list_fields,test__redact_pii_matches_malformed_response,test_should_raise_guardrail_blocked_exception_null_fields) are declaredasync defand decorated with@pytest.mark.asyncio, but they only call synchronous functions — noawaitanywhere in their bodies. This creates a trivial asyncio event-loop per test with no benefit. Consider droppingasync def/@pytest.mark.asynciofor these three functions to keep them consistent with normal unit tests.
Reviews (1): Last reviewed commit: "resolve merge conflicts: keep null-safet..." | Re-trigger Greptile
Closes #24147 — resolving merge conflicts from the original PR.
Changes
bedrock_guardrails.py: null-safety fixes foror []fallback on list fields (regexes,piiEntities,topics,filters,customWords,managedWordLists) that Bedrock can return as explicitNoneTestRedactPiiMatchesNullSafety,TestShouldRaiseGuardrailBlockedExceptionNullSafety,TestApplyGuardrailNullSafety_extract_blocked_assessmentsand_get_http_exception_for_blocked_guardrailPre-Submission Checklist
make test-unitpasses locallyType