feat(bedrock): add first-class guardrail configuration support#899
Open
dermdunc wants to merge 2 commits intoanthropics:mainfrom
Open
feat(bedrock): add first-class guardrail configuration support#899dermdunc wants to merge 2 commits intoanthropics:mainfrom
dermdunc wants to merge 2 commits intoanthropics:mainfrom
Conversation
Add guardrailIdentifier and guardrailVersion as ClientOptions for AnthropicBedrock, enabling Bedrock Guardrails without relying on custom header workarounds. Headers are injected in buildRequest() before SigV4 signing. Env var fallback via BEDROCK_GUARDRAIL_IDENTIFIER and BEDROCK_GUARDRAIL_VERSION. Closes anthropics/claude-code#23322 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add symmetric validation: throw when guardrailVersion is set without guardrailIdentifier (previously only the reverse was checked) - Add trace option (ENABLED/DISABLED/ENABLED_FULL) with X-Amzn-Bedrock-Trace header and BEDROCK_TRACE env var - Move jest.resetModules() to beforeEach for consistency across tests - Add test for version-only misconfiguration scenario - Add 4 trace-specific tests (constructor, ENABLED_FULL, env var, trace-independent-of-guardrails) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
guardrailIdentifierandguardrailVersionas first-classClientOptionsonAnthropicBedrock, enabling Bedrock Guardrails without relying on custom header workaroundsX-Amzn-Bedrock-GuardrailIdentifierandX-Amzn-Bedrock-GuardrailVersionheaders inbuildRequest()before SigV4 signingBEDROCK_GUARDRAIL_IDENTIFIERandBEDROCK_GUARDRAIL_VERSIONguardrailVersionis required whenguardrailIdentifieris setMotivation
Users of Claude Code and the Bedrock SDK need to apply AWS Bedrock Guardrails to model invocations. The current workaround (
ANTHROPIC_CUSTOM_HEADERS) is insufficient for IAM policy enforcement because AWS IAM condition keys (bedrock:GuardrailIdentifier) evaluate against request context populated by the API parameter layer, not raw HTTP headers. See anthropics/claude-code#23322.Changes
packages/bedrock-sdk/src/client.tsClientOptionstype withguardrailIdentifierandguardrailVersion(with JSDoc)AnthropicBedrockclassbuildRequest()injects guardrail headers inside theMODEL_ENDPOINTSblockpackages/bedrock-sdk/tests/guardrails.test.ts— 8 test cases covering:packages/bedrock-sdk/examples/guardrails.ts— Usage examplepackages/bedrock-sdk/README.md— Guardrails documentation sectionTest plan
npx jestinpackages/bedrock-sdk/)./buildinpackages/bedrock-sdk/)🤖 Generated with Claude Code