litellm - 💡(How to fix) Fix [Feature]: Bedrock Guardrails contextual grounding via the guardrail hook (request-side qualifiers) [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

RAG / summarization / QA apps routing Bedrock through LiteLLM want to block hallucinated answers at the proxy. Today they cannot, because there is no way to tell the guardrail which message text is the grounding source vs. the query.

Fix Action

Fixed

RAW_BUFFERClick to expand / collapse

The Feature

Amazon Bedrock Guardrails' contextual grounding check stops hallucinations by scoring a model response against a reference source (grounding_source) and the user question (query). The ApplyGuardrail / Converse API expresses this by tagging each content block with a qualifiers array (grounding_source / query / guard_content).

The Bedrock guardrail hook (litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py) currently sends guardrail content as plain text with no qualifiers, so contextual grounding cannot be driven through the proxy guardrails: config — even though the response side is already wired (_extract_blocked_assessments / _should_raise_guardrail_blocked_exception already parse contextualGroundingPolicy and block on it).

So grounding is "half-wired": responses are handled, but requests can't carry the grounding source/query. This issue tracks completing the request side.

Motivation, pitch

RAG / summarization / QA apps routing Bedrock through LiteLLM want to block hallucinated answers at the proxy. Today they cannot, because there is no way to tell the guardrail which message text is the grounding source vs. the query.

Proposed (mirrors the existing guarded_text selective-guarding marker): let callers tag message content blocks {"type": "grounding_source", "text": ...} and {"type": "query", "text": ...}. At post_call the hook assembles one ApplyGuardrail(source="OUTPUT") carrying the grounding source + query + the model response (as guard_content). Requests without these tags produce a byte-identical payload, so existing behaviour is unchanged.

Are you a ML Ops Team?

No

Twitter / LinkedIn details

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING