fix(guardrails): improve CrowdStrike AIDR input handling#25244
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Merging this PR will not alter performance
Comparing |
Greptile SummaryThis PR refactors the CrowdStrike AIDR guardrail to use typed Pydantic models (
Confidence Score: 4/5Safe to merge pending confirmation that The Pydantic model additions and serialization improvements are clean. The one P1 concern is the removal of the litellm/proxy/guardrails/guardrail_hooks/crowdstrike_aidr/crowdstrike_aidr.py — specifically
|
| Filename | Overview |
|---|---|
| litellm/proxy/guardrails/guardrail_hooks/crowdstrike_aidr/crowdstrike_aidr.py | Introduces typed Pydantic models for request serialization and simplifies response handling, but removes the body.messages and logging_obj fallback lookups for conversation history in the response path, which may silently send empty history to the AIDR API. |
| tests/test_litellm/proxy/guardrails/guardrail_hooks/test_crowdstrike_aidr.py | Tests correctly updated to reflect the new unified-messages API shape (no choices key); mock-only, no real network calls. Coverage is equivalent to the old tests. |
Sequence Diagram
sequenceDiagram
participant Proxy
participant Handler as CrowdStrikeAIDRHandler
participant AIDR as CrowdStrike AIDR API
alt input_type == request
Proxy->>Handler: apply_guardrail(inputs, request_data, request)
Handler->>Handler: _build_guard_input_for_request(inputs)
Note over Handler: structured_messages → _normalize_content()<br/>OR texts → list[_Message]<br/>Empty-content messages filtered out
Handler->>AIDR: POST /v1/guard_chat_completions
AIDR-->>Handler: result blocked/transformed/guard_output
alt blocked
Handler-->>Proxy: raise HTTPException(400)
else transformed
Handler->>Handler: Extract texts from guard_output messages
Handler-->>Proxy: texts: transformed_texts
else not transformed
Handler-->>Proxy: original inputs
end
else input_type == response
Proxy->>Handler: apply_guardrail(inputs, request_data, response)
Handler->>Handler: _build_guard_input_for_response(inputs, request_data)
Note over Handler: history = request_data.get(messages, [])<br/>Append assistant messages from inputs texts
Handler->>AIDR: POST /v1/guard_chat_completions
AIDR-->>Handler: result blocked/transformed/guard_output
alt blocked
Handler-->>Proxy: raise HTTPException(400)
else transformed
Handler->>Handler: _extract_transformed_texts(guard_output, num_assistant)
Handler-->>Proxy: texts: transformed_texts
else not transformed
Handler-->>Proxy: original inputs
end
end
Reviews (5): Last reviewed commit: "fix(guardrails): improve CrowdStrike AID..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
ff6bbeb to
057186e
Compare
Added stricter data models to ensure that everything is converted to the format that the CrowdStrike AIDR API expects. Also greatly simplified how LLM responses are handled while fixing streaming responses at the same time.
057186e to
315c657
Compare
|
Reopened at #26658 since the |
Pre-Submission checklist
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🧹 Refactoring
Changes
Added stricter data models to ensure that everything is converted to the format that the CrowdStrike AIDR API expects. Also greatly simplified how LLM responses are handled while fixing streaming responses at the same time.