feat: add native AWS Bedrock Guardrails support to ModelConfig#2323
feat: add native AWS Bedrock Guardrails support to ModelConfig#2323sanskar-singh-2403 wants to merge 5 commits into
Conversation
66094cc to
ff7ec17
Compare
|
@peterj @dmitri-d @davidkarlsen can we review this? Thanks! |
|
|
||
| type BedrockGuardrailConfig struct { | ||
| // +required | ||
| // +kubebuilder:validation:MinLength=1 |
There was a problem hiding this comment.
nit: add a max length too, since it's set on the aws config.
There was a problem hiding this comment.
(i wonder if we'd need the actual regex for the full arn); but i see it's either a string OR arn, so that might look too complex
There was a problem hiding this comment.
hey @peterj
Good call, added MaxLength to both fields:
identifier:MaxLength=2048(AWS's cap onguardrailIdentifier)version:MaxLength=8(numeric version orDRAFT)
Regenerated the CRD manifests and synced the helm copy.
On the ARN regex: you are right I left it out on purpose. AWS's real pattern is a
bare-ID branch OR a full-ARN branch:
^(([a-z0-9]+)|(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:[0-9]{12}:guardrail/[a-z0-9]+))$
Baking that into a kubebuilder Pattern would reject at admission, but
AWS already validates the identifier on the Converse call and returns a
clear error. A strict regex mostly adds risk of false rejections (GovCloud
/China partitions, future ARN shapes) for little gain, and as you noted it
reads as noise. The MinLength=1 / MaxLength=2048 bound catches the
empty/garbage cases cheaply and defers real validation to AWS.
There was a problem hiding this comment.
can we re-run the CI?
Add an optional guardrail block to the Bedrock provider in ModelConfig so the controller passes GuardrailConfiguration to the Converse and ConverseStream APIs natively, without requiring an external proxy. - v1alpha2: new BedrockGuardrailConfig (identifier+version required, trace enum disabled/enabled/enabled_full, default disabled) - adk types + translator + agent wiring - Converse uses GuardrailConfiguration; ConverseStream uses GuardrailStreamConfiguration with sync processing so interventions apply before content is streamed - regenerated deepcopy + CRD manifests, synced helm CRD copy - unit tests for both guardrail builders and ADK JSON marshalling Fixes kagent-dev#2320 Signed-off-by: Sanskar Singh <sanskarsinghty1234@gmail.com>
964014b to
932fbc4
Compare
|
@peterj should we merge? If everything seems fine 😸 |
EItanya
left a comment
There was a problem hiding this comment.
Hey there, to be honest I don't think guardrails belong inside of kagent. If we start adding guardrails the scope may blow up. I think this belongs at the network level. i would look into https://agentgateway.dev/
hey @EItanya thanks for taking a look, and totally fair concern. I want to make sure I am not This isn't adding a guardrails engine or any filtering logic to kagent. It exposes So my worry with pushing this to the network layer only: for someone who is on the That said, I hear you on keeping traffic-plane concerns in agentgateway, and I don't |
Add an optional guardrail block to the Bedrock provider in ModelConfig so the controller passes GuardrailConfiguration to the Converse and ConverseStream APIs natively, without requiring an external proxy. - v1alpha2: new BedrockGuardrailConfig (identifier+version required, trace enum disabled/enabled/enabled_full, default disabled) - adk types + translator + agent wiring - Converse uses GuardrailConfiguration; ConverseStream uses GuardrailStreamConfiguration with sync processing so interventions apply before content is streamed - regenerated deepcopy + CRD manifests, synced helm CRD copy - unit tests for both guardrail builders and ADK JSON marshalling Fixes kagent-dev#2320 Signed-off-by: Sanskar Singh <sanskarsinghty1234@gmail.com>
…singh-2403/kagent into feat/bedrock-guardrails
hey @EItanya any thoughts on this? |
What this PR does
Adds an optional
guardrailblock to the Bedrock provider inModelConfig, so thecontroller passes the guardrail config to the Bedrock Converse and ConverseStream
APIs natively. This removes the need to stand up a separate OpenAI-compatible proxy just
to apply AWS Bedrock Guardrails (content filtering, denied topics, PII redaction) to an
agent.
Example config:
Changes
api/v1alpha2: newBedrockGuardrailConfigtype onBedrockConfig.identifierand
versionare required within the block (MinLength=1); the whole block is optional.traceis a typed enum (disableddefault /enabled/enabled_full) mapping to theSDK's
GuardrailTrace.api/adk: matchingBedrockGuardrailtransport struct onBedrock,omitempty.v1alpha2-> adk ->runtime
BedrockConfig, nil-guarded so existing configs are unaffected.adk/pkg/models/bedrock.go: build the guardrail config and attach it to both APIcalls. Note the SDK uses two different types here
Conversetakestypes.GuardrailConfiguration, whileConverseStreamtakestypes.GuardrailStreamConfiguration. The stream path usesStreamProcessingMode: syncso guardrail interventions are applied before content is streamed to the caller,
rather than leaking blocked content. Per the issue discussion, interventions surface in
the response content (not as a hard error) so the agent loop isn't broken.
zz_generated.deepcopy.goand theModelConfigCRD (controller-genv0.19.0), and synced the
helm/kagent-crdscopy.Tests
bedrockGuardrailConfig,bedrockGuardrailStreamConfig) covering the nil / set / empty-trace / stream-mode cases.guardrailblock (present and omitted-when-nil).go build,go vet, andgo testpass forapi/adk,adk/pkg/models, and thecontroller translator package;
gofmtclean.Notes for reviewers
use
InvokeModel, so it was intentionally left out (matches the issue scope).(content filters, topic denial, PII redaction) in their environment happy to
coordinate on that.
Fixes #2320