Skip to content

[Feature]: Logging the Bedrock guardrail response in DB #13690

@willdlange

Description

@willdlange

The Feature

Capture and log complete Guardrail api response in DB.

At the moment, this information is missing from the request metadata in litellm.

Example response from Bedrock Guardrail API:

{
"ResponseMetadata": {
"RequestId": "e548ae43-6556-4d94-9b7c-.......",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"date": "Fri, 15 Aug 2025 14:00:32 GMT",
"content-type": "application/json",
"content-length": "1079",
"connection": "keep-alive",
"x-amzn-requestid": "e548ae43-6556-4d94-9b7c-......."
},
"RetryAttempts": 0
},
"usage": {
"topicPolicyUnits": 0,
"contentPolicyUnits": 1,
"wordPolicyUnits": 1,
"sensitiveInformationPolicyUnits": 1,
"sensitiveInformationPolicyFreeUnits": 0,
"contextualGroundingPolicyUnits": 0
},
"action": "GUARDRAIL_INTERVENED",
"actionReason": "Guardrail blocked.",
"outputs": [
{
"text": "Sorry, I cannot answer this question."
}
],
"assessments": [
{
"contentPolicy": {
"filters": [
{
"type": "INSULTS",
"confidence": "HIGH",
"filterStrength": "HIGH",
"action": "BLOCKED",
"detected": true
}
]
},
"invocationMetrics": {
"guardrailProcessingLatency": 270,
"usage": {
"topicPolicyUnits": 0,
"contentPolicyUnits": 1,
"wordPolicyUnits": 1,
"sensitiveInformationPolicyUnits": 1,
"sensitiveInformationPolicyFreeUnits": 0,
"contextualGroundingPolicyUnits": 0
},
"guardrailCoverage": {
"textCharacters": {
"guarded": 36,
"total": 36
}
}
}
}
],
"guardrailCoverage": {
"textCharacters": {
"guarded": 36,
"total": 36
}
}
}

Motivation, pitch

We require some of the fields emitted in the Bedrock ApplyGuardrail API response, for governance.
https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ApplyGuardrail.html

For example, being able to log and monitor the type of Guardrail policy that was detected (Eg. insults) and the type of action that has been taken (eg. blocked).

LiteLLM is hiring a founding backend engineer, are you interested in joining us and shipping to all our users?

No

Twitter / LinkedIn details

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions