Skip to content

Conversation

Sameerlite
Copy link
Contributor

@Sameerlite Sameerlite commented Sep 15, 2025

Bedrock GuardrailConverseContent Support Implementation

Relevant issues

Fixes #12676

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

Local Test

Screenshot 2025-09-16 at 10 57 46 PM

Type

🆕 New Feature
🐛 Bug Fix

Changes

  1. litellm/litellm/types/llms/bedrock.py

    • Added GuardrailConverseContentBlock type definition
    • Updated ContentBlock to include guardrailConverseContent field
  2. litellm/litellm/litellm_core_utils/prompt_templates/factory.py

    • Updated _bedrock_converse_messages_pt function to support guarded_text content type
    • Updated _bedrock_converse_messages_pt_async function for async support
    • Added logic to wrap guarded_text content in GuardrailConverseContent blocks

Features Implemented

When guarded_text content type is encountered:

  1. The text content is extracted from the guarded_text block
  2. A new BedrockContentBlock is created with guardrailConverseContent field
  3. The content is wrapped as: {"guardrailConverseContent": {"text": "..."}}
  4. Other content types (text, image_url, etc.) are processed normally

Usage:

import litellm
from litellm import completion

messages = [
    {
        "role": "system",
        "content": "You are a helpful AI assistant."
    },
    {
        "role": "user",
        "content": [
            {"type": "text", "text": "What is the main topic of this legal document?"},
            {"type": "guarded_text", "text": "This is a set of very long instructions that you will follow. Here is a legal document that you will use to answer the user's question."}
        ]
    }
]

response = completion(
    model="bedrock/converse/us.amazon.nova-pro-v1:0",
    messages=messages,
    guardrailConfig={
        "guardrailIdentifier": "gr-abc123",
        "guardrailVersion": "DRAFT"
    }
)

Copy link

vercel bot commented Sep 15, 2025

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

Project Deployment Preview Comments Updated (UTC)
litellm Ready Ready Preview Comment Sep 16, 2025 6:21pm

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.

reviewed

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.

[Feature]: Add GuardrailConverseContent Support for Bedrock Guardrails to supportive selective Guarding
2 participants