{"record":{"id":"0bcf52a5ff64ff43","repo":"BerriAI/litellm","slug":"bedrock-guardrail-failed-e","errorCode":null,"errorMessage":"Bedrock guardrail failed: {e}","messagePattern":"Bedrock guardrail failed: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py","lineNumber":3093,"sourceCode":"                scanned_role_subset=scanned_role_subset,\n            )\n\n            verbose_proxy_logger.debug(\"Bedrock Guardrail: Successfully applied guardrail\")\n\n            inputs[\"texts\"] = masked_texts\n            return inputs\n\n        except (HTTPException, ModifyResponseException):\n            # Let guardrail blocking exceptions propagate as-is so the proxy can\n            # return the correct HTTP status (400 for HTTPException, 200 with the\n            # block message for ModifyResponseException in disable_exception_on_block\n            # mode). Without this, the generic except below wraps them into a plain\n            # Exception, losing the semantics and preventing the proxy from\n            # properly blocking the call.\n            raise\n        except Exception as e:\n            verbose_proxy_logger.error(\"Bedrock Guardrail: Failed to apply guardrail: %s\", str(e))\n            raise Exception(f\"Bedrock guardrail failed: {e}\")\n","sourceCodeStart":3075,"sourceCodeEnd":3094,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py#L3075-L3094","documentation":"This is a catch-all wrapper raised by the Bedrock guardrail hook in litellm's proxy when ANY unexpected exception occurs while applying the guardrail (i.e., calling bedrock:ApplyGuardrail and processing its response). HTTPException and ModifyResponseException are deliberately re-raised untouched, so this generic Exception only fires for operational failures: AWS credential errors, AccessDeniedException on the guardrail ARN, ThrottlingException, guardrail-not-found in the configured region, network failures, or bugs parsing the Bedrock response. The original exception text is preserved in the message but the exception type is flattened to a plain Exception.","triggerScenarios":"A request routes through a deployment with a bedrock guardrail attached (guardrails: [bedrock]) and the underlying boto3 ApplyGuardrail call fails: expired/missing AWS credentials, guardrail_id/guardrailVersion not present in the aws_region_name, IAM policy missing bedrock:ApplyGuardrail, throttling, or a response payload that violates the parsing code's expectations. Raised from async_apply_guardrail during pre_call/post_call hooks.","commonSituations":"Typical after adding a Bedrock guardrail entry to config.yaml with a typo'd guardrail_id, omitting aws_region_name (defaults to a region where the guardrail does not exist), running the proxy in an environment without AWS credentials (no AWS_PROFILE/instance role), or hitting AWS throttling under load. Also appears after litellm upgrades that change the expected ApplyGuardrail response shape.","solutions":["Check the proxy logs for the preceding line 'Bedrock Guardrail: Failed to apply guardrail: <e>' — the original error (e.g., AccessDeniedException, ExpiredToken) tells you the real cause; fix that (credentials, IAM bedrock:ApplyGuardrail permission, guardrail_id/version, region).","Verify the guardrail exists and is enabled in the region you configured: aws bedrock get-guardrail --guardrail-identifier <id> --guardrail-version <v> --region <region>.","If the error is transient (ThrottlingException, timeouts), raise AWS retry capacity or attach multiple guardrail attempts via litellm's guardrail retry settings / circuit breaker config.","If the failure persists and you want the request to proceed without scanning, remove/disable the guardrail for that deployment (guardrails: [] on the model or mode: passthrough off) rather than letting every call fail.","Upgrade litellm to the latest patch if the inner exception indicates a parsing bug in the guardrail response handling."],"exampleFix":"# config.yaml — before (guardrail missing region + wrong id)\nguardrails:\n  - guardrail_name: bedrock-pii\n    litellm_params:\n      guardrail: bedrock\n      guardrail_id: arn:aws:bedrock:us-east-1:1234:guardrail/GRDMOCK\n      guardrailVersion: DRAFT\n\n# after — explicit region matching the guardrail, valid version\n guardrails:\n  - guardrail_name: bedrock-pii\n    litellm_params:\n      guardrail: bedrock\n      guardrail_id: arn:aws:bedrock:us-west-2:1234:guardrail/GRDMOCK\n      guardrailVersion: \"1\"\n      aws_region_name: us-west-2","handlingStrategy":"try-catch","validationCode":"# Pre-flight the guardrail before attaching it to traffic\nimport boto3, os\nclient = boto3.client(\"bedrock-runtime\", region_name=os.environ.get(\"AWS_REGION\", \"us-east-1\"))\nclient.get_guardrail(guardrailIdentifier=\"<your-guardrail-id>\")  # raises if missing/permissions bad\n# ensure runtime credentials exist\nassert client._request_signer._credentials is not None, \"no AWS credentials\"","typeGuard":null,"tryCatchPattern":"try:\n    resp = await litellm.acompletion(model=\"anthropic/claude-...\", messages=msgs, guardrails=[\"bedrock-pii\"])\nexcept Exception as e:  # generic Exception is all this wrapper gives you\n    if \"Bedrock guardrail failed:\" in str(e):\n        inner = str(e).split(\"Bedrock guardrail failed:\", 1)[1].strip()\n        if \"ThrottlingException\" in inner or \"Timeout\" in inner:\n            await asyncio.sleep(1); resp = await retry_call()\n        elif \"AccessDenied\" in inner or \"ExpiredToken\" in inner:\n            alert_ops(f\"guardrail IAM/creds broken: {inner}\")\n        else:\n            raise","preventionTips":["Run `aws bedrock get-guardrail` with the proxy's IAM role before each deploy to prove guardrail_id/version/region are valid.","Grant the proxy role only bedrock:ApplyGuardrail on the specific guardrail ARN and alarm on AccessDenied in logs.","Load-test guardrail-attached routes so AWS throttling limits are raised before peak traffic.","Pin the litellm version and read guardrail changelogs on upgrade — response parsing changes live here."],"tags":["litellm","bedrock","guardrails","aws","proxy","configuration"],"backgroundTag":"guardrail-api-failure","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}