Repository navigation
fix(proxy): redact guardrail-blocked request body from spend logs - #50214
Open
shadowmodder wants to merge 11 commits into
Open
shadowmodder wants to merge 11 commits into
shadowmodder wants to merge 11 commits into
Conversation
Contributor
…cked_spend_logs # Conflicts: # litellm/proxy/common_request_processing.py # tests/unit/proxy/test_common_request_processing.py
…r merging main Merging main left _pre_call_with_fallbacks one branch over the strict complexity limit, so the guardrail check moves into a small helper used by both call sites. redact_blocked_request_body_snapshot only reads its argument, so it now takes a Mapping, which clears the LIT001 finding on its signature.
DynamoAI blocks raised a plain ValueError, which is_guardrail_intervention does not recognize, so guardrail-blocked request bodies from DynamoAI skipped the spend-log redaction this PR adds. The three violations_detected sites now raise GuardrailRaisedException with blocked_content set and the same error message text. Signed-off-by: shadowmodder <sudhirvissa@gmail.com>
Same change as the previous commit, stored as plain source (the previous write stored the content base64-encoded). Signed-off-by: shadowmodder <sudhirvissa@gmail.com>
Signed-off-by: shadowmodder <sudhirvissa@gmail.com>
Contributor
Author
|
Fixed both. DynamoAI blocks now raise GuardrailRaisedException with blocked_content set, and dynamoai.py is restored as plain source after an encoding slip in the previous write. |
…locked_spend_logs # Conflicts: # litellm/proxy/common_request_processing.py
# Conflicts: # litellm/proxy/common_request_processing.py # tests/unit/proxy/test_common_request_processing.py
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a proxy operator with spend-log prompt storage enabled cannot stop blocked secrets reaching the logs
After: the same blocked request leaves only a redacted placeholder in the logs
Relevant issues
Fixes #50127
Pre-Submission checklist
uv run pytest tests/unit/proxy/test_common_request_processing.py tests/unit/proxy/test_litellm_pre_call_utils.py(1254 passed). Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
E2E exception at b91bc972
python /tmp/repro_50127.pydrives common_processing_pre_call_logic with a mocked pre_call_hook raising GuardrailRaisedException and HTTPException 400, each carrying a fake secret. Before the fix the stored body held the raw prompt with the secret. After the fix both cases store {"model": "small", "[redacted]": "blocked by guardrail"} and the secret appears nowhere in the stored bodyRed-then-green mutation proof:
pytest tests/unit/proxy/test_common_request_processing.py tests/unit/proxy/test_litellm_pre_call_utils.py -k "redacts_blocked_request_body or keeps_body_on_non_guardrail or redact_blocked_request_body_snapshot": 5 passedType
🐛 Bug Fix
Caveats (if any)
Low
Final Attestation
Follow-up fix (veria-ai review)
_pre_call_with_fallbacksthen restored the original unredacted snapshot (self.data = rate_limited_data), so the blocked prompt could still reach the failure logs. Fixed by redacting the restored snapshot too when the fallback raises a guardrail intervention.test_fallback_guardrail_block_redacts_restored_request_body(fails without the fix, passes with it).Update: DynamoAI guardrails
DynamoAI blocks raised a plain ValueError, which the redaction check does not recognize as a guardrail intervention. The hook now raises GuardrailRaisedException with blocked_content set and the same error message, so DynamoAI-blocked bodies are redacted from spend logs too. Its tests assert the intervention contract.