Skip to content

Conversation

@Sameerlite
Copy link
Collaborator

Title

Implement Bedrock Guardrail apply_guardrail endpoint support

Relevant issues

Fixes LIT-1348

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

🆕 New Feature

Changes

Summary

This PR implements the missing /guardrails/apply_guardrail endpoint support for Bedrock Guardrails, allowing users to test guardrail performance without making actual LLM calls.

Key Changes

1. Added apply_guardrail method to BedrockGuardrail class

  • File: litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py
  • Changes:
    • Implemented async def apply_guardrail() method that was missing
    • Added proper Bedrock API integration for testing
    • Handles content blocking and masking scenarios
    • Extracts masked content from Bedrock response output field
    • Includes comprehensive error handling

Example Usage

curl -X POST 'http://localhost:4000/guardrails/apply_guardrail' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer your-api-key' \
-d '{
    "guardrail_name": "bedrock-content-guard",
    "text": "This message contains sensitive card number 1234 information",
    "language": "en"
}'

# Response:
{
    "response_text": "This message contains sensitive card number {CREDIT_DEBIT_CARD_NUMBER} information"
}
Screenshot 2025-10-24 at 2 34 41 PM

@vercel
Copy link

vercel bot commented Oct 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
litellm Ready Ready Preview Comment Oct 24, 2025 9:40am

Copy link
Contributor

@ishaan-jaff ishaan-jaff left a comment

Choose a reason for hiding this comment

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

LGTM

@ishaan-jaff ishaan-jaff merged commit c638f45 into main Oct 24, 2025
34 of 53 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.

2 participants