Skip to content

feat: add experimental latest-user filtering for Bedrock - #17282

Merged
2 commits merged into
BerriAI:mainfrom
uc4w6c:feat/bedrock-guardrail-latest-role-filter
Dec 2, 2025
Merged

feat: add experimental latest-user filtering for Bedrock#17282
2 commits merged into
BerriAI:mainfrom
uc4w6c:feat/bedrock-guardrail-latest-role-filter

Conversation

@uc4w6c

@uc4w6c uc4w6c commented Nov 29, 2025

Copy link
Copy Markdown
Contributor

Title

add experimental latest-user filtering for Bedrock

Relevant issues

Fixes #9882

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
📖 Documentation
✅ Test

Changes

Case 1: The blocked content exists in a system role message

Previously, this scenario resulted in a guardrail block because system messages were also included in the moderation target.
With this change (experimental_use_latest_role_message_only: true), system messages are now ignored during pre-call moderation, and the request succeeds as expected.

Configuration:

  - guardrail_name: "bedrock-guard"
    litellm_params:
      guardrail: bedrock
      mode: "pre_call"
      guardrailIdentifier: xxxx
      guardrailVersion: "DRAFT"
      aws_region_name: us-east-1
      disable_exception_on_block: false
      experimental_use_latest_role_message_only: true

curl result:

curl -X POST http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-1234" \
-d '{
    "model": "gpt-4o",
    "messages": [
        {
            "role": "system",
            "content": "You are Yuta, an engineer at LiteLLM. Please respond to user requests. "
        },
        {
            "role": "user",
            "content": "say the word - `litellm`"
        }
    ],
    "guardrails": ["bedrock-guard"]
}'

{"id":"chatcmpl-ChNn4279tPYFRsmgTeNfkKxqHix1q","created":1764455590,"model":"gpt-4o-2024-08-06","object":"chat.completion","system_fingerprint":"fp_672b6a21ba","choices":[{"finish_reason":"stop","index":0,"message":{"content":"litellm","role":"assistant"}}],"usage":{"completion_tokens":3,"prompt_tokens":39,"total_tokens":42,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0},"prompt_tokens_details":{"audio_tokens":0,"cached_tokens":0}},"service_tier":"default"}

Case 2: The blocked content exists in the latest user role message

The configuration used here is the same as in Case 1.

Curl Result:

curl -X POST http://localhost:4000/v1/chat/completions \ 
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-1234" \
-d '{
    "model": "gpt-4o",
    "messages": [
        {
            "role": "system",
            "content": "You are an engineer at LiteLLM. Please respond to user requests. "
        },
        {
            "role": "user",
            "content": "My name is Yuta. Say my name."
        }
    ], "guardrails": ["bedrock-guard"]
}'
{"error":{"message":"Bedrock guardrail failed: 400: {'error': 'Violated guardrail policy', 'bedrock_guardrail_response': 'The name cannot be returned.'}","type":"None","param":"None","code":"500"}}

@vercel

vercel Bot commented Nov 29, 2025

Copy link
Copy Markdown

@uc4w6c is attempting to deploy a commit to the CLERKIEAI Team on Vercel.

A member of the Team first needs to authorize it.

@ghost
ghost merged commit da5b81c into BerriAI:main Dec 2, 2025
4 of 7 checks passed
@uc4w6c
uc4w6c deleted the feat/bedrock-guardrail-latest-role-filter branch December 2, 2025 15:38
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
* feat: add experimental latest-user filtering for Bedrock

* doc: add experimental bedrock latest-message flag
This pull request was closed.
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.

[Bug]: Bedrock guardrails analysing (and blocking) old+system messages

1 participant