Repository navigation
fix(guardrails): read per-request extra_body from the proxy request in the generic guardrail api - #52438
Conversation
|
[AI] @greptileai review Generated by Claude Code |
There was a problem hiding this comment.
🔍 Devin Review: 1 flag
Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
[Medium impact] The change affects per-request settings in the generic guardrail workflow. The code fix looks sound, but the test must meet the repository's dependency injection requirement before merging. Findings
|
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
e6ce763 to
6696d38
Compare
…n the generic guardrail api
6696d38 to
66b3a3d
Compare
|
At |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
nate seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Handwritten 1-3 sentence description
The helper for getting dynamic request body parameters expects the
request_data, not the 'body' key, which will always be missing.Details
Link to Devin session: https://app.devin.ai/sessions/adba21fa9e7a4483b813c98b2ac8349b
Open in Devin Desktop: https://app.devin.ai/desktop/session/adba21fa9e7a4483b813c98b2ac8349b?variant=devin
Requested by: @narmstrong-berri
TLDR
Problem this solves:
extra_bodynever reaches a generic guardrail servicebodykey proxy requests lackHow it solves it:
User Flow
Before: a developer tuning a generic guardrail per request sees their settings ignored
my-guard"guardrails": [{"my-guard": {"extra_body": {"threshold": 0.7}}}]thresholdAfter: the guardrail service receives the per-request settings
threshold: 0.7inadditional_provider_specific_params, next to the configured paramsPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
E2E exception at e6ce763
Scope is one call in
GenericGuardrailAPI.apply_guardrail(litellm/proxy/guardrails/guardrail_hooks/generic_guardrail_api/generic_guardrail_api.py). It passedrequest_data.get("body") or {}toget_guardrail_dynamic_request_body_params, but no caller in the repo puts abodykey inrequest_data, so the lookup always saw an empty dict. It now passesrequest_data, which is what Lakera, Noma, Presidio and Gray Swan already pass to the same method. That method reads theguardrailslist from the request root, else frommetadataandlitellm_metadata, so pre-call and post-call request shapes both resolve. The premium gate on dynamicextra_bodyis unchanged.The bug was found by the Dec 1 integration contract tests (draft PR #50853). The test skipped with BUG for it is
tests/integration/observability/test_dec1_guardrails_modes.py::test_a_dict_entry_passes_its_extra_body_to_the_guardrail_service.The new regression test
test_per_request_extra_body_from_a_proxy_request_reaches_the_guardrail_servicecallsapply_guardrailwith a proxy-shaped request naming the guardrail with{"extra_body": {"success_threshold": 0.9}}, against a mocked guardrail endpoint, and checks the body sent carries it inadditional_provider_specific_params. It failed before the fix (the service got{}) and passes at the tip.Type
Bug Fix
Final Attestation
Generated by Claude Code