Skip to content

[Bug Fix] Bedrock Guardrail - Don't raise exception on intervene action #11875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 24, 2025

Conversation

ishaan-jaff
Copy link
Contributor

@ishaan-jaff ishaan-jaff commented Jun 19, 2025

[Bug Fix] Bedrock Guardrail - Don't raise exception on intervene action

Screenshot 2025-06-23 at 7 55 05 PM

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix
✅ Test

Changes

Copy link

vercel bot commented Jun 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2025 2:59am

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ ishaan-jaff
❌ cursoragent
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug with the Bedrock Guardrail not correctly handling intervention actions by only raising exceptions for BLOCKED actions and leaving ANONYMIZED actions untouched. It also introduces new tests to verify the guardrail’s behavior and updates several methods to improve code readability and consistency.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/guardrails_tests/test_bedrock_guardrails.py Added tests to validate that only BLOCKED actions trigger exceptions and that masking with anonymized responses work as expected
litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py Revised guardrail exception logic to only raise exceptions on BLOCKED actions and updated message-masking functions with clearer formatting

# Should use the masked content from guardrail output
assert response is not None
assert response["messages"][0]["content"] == "Hello, my phone number is {PHONE} and email is {EMAIL}"
print("✅ Masked output was applied even without masking flags enabled")
Copy link
Preview

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider replacing the print statement with a logger call to maintain consistency with the rest of the codebase's logging practices.

Suggested change
print("✅ Masked output was applied even without masking flags enabled")
logger.info("✅ Masked output was applied even without masking flags enabled")

Copilot uses AI. Check for mistakes.

@ishaan-jaff ishaan-jaff merged commit d677a6b into main Jun 24, 2025
9 of 46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants