fix: bedrock converse-stream reports a guardrail block as guardrail_intervened #10036
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.47) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 490 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.371
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #10036"
general
weight: 0.35
mansur-akhmadi
Summary
When a Bedrock guardrail blocks a turn,
/bedrock/model/{modelId}/converse-streamended the stream withmessageStop.stopReason: "content_filtered". Bedrock ConverseStream sends"guardrail_intervened", and non-streaming/conversealready returns that.FinalizeBedrockStreammaps bothguardrail_intervenedandcontent_filterto the sameIncompleteDetails{Reason: "content_filter"}and keeps the original value onStopReason. TheToBedrockConverseStreamResponseterminal arm lets recognized incomplete details win overStopReason, so both come out ascontent_filtered.restoreBedrockNativeStopReasononly acts onend_turn, so it doesn't undo this.Changes
core/providers/bedrock/responses.go: in the converse-stream terminal arm, when the details map tocontent_filteredand the explicit stop reason isguardrail_intervened, keepguardrail_intervened. Everything else keeps the current order. That covers an Anthropicrefusaland a modelcontent_filter, which both staycontent_filtered, andmax_output_tokensdetails, which still givemax_tokens.core/providers/bedrock/conversestreamstop_test.go:TestConverseStreamGuardrailStopReason.tests/e2e/api/collections/provider-harness.json: folder 390, a/conversecontrol case and the/converse-streamcase, both using the same blocked prompt andguardrailConfigas the existing guardrail cases.core/changelog.md: entry.Cost: one string compare and one nil check on the terminal event of a stream whose incomplete details are
content_filter. Nothing on other events, no allocations, nothing retained.BenchmarkConverseStreamEndTurn(-benchmem -count=5, M-series): 103 allocs/op before and after, and ns/op is within noise (median 2917 vs 3002 ns/op). The end_turn path never reaches the new branch.Type of change
Affected areas
How to test
TestConverseStreamGuardrailStopReasonreplays a ConverseStream answer ending inguardrail_intervened,content_filteredandmax_tokensthrough the upstream converter,FinalizeBedrockStreamand the converse-stream egress. It also feeds the egress directly with the stop reason / incomplete details combinations above.dev: FAIL. The guardrail round trip gives{"stopReason":"content_filtered"}, andguardrail_intervenedpluscontent_filterdetails givecontent_filtered.content_filtered,content_filter,max_tokensand no-details cases are unchanged.go vetand gofmt are clean, and golangci-lint reports 0 issues on the change.Harness: folder 390 passes
augment-provider-harness.mjsandfilter-collection.mjs --provider bedrock --feature "guardrail stop reason"keeps both cases. The/converse-streamcase should be red ondevand green here. I didn't run it live:Routes not covered here: the InvokeModel routes (#9495) and
/anthropic/v1/messages(#9497) map a guardrail block differently. Those are separate issues, and this change doesn't touch their encoders.Breaking changes
Related issues
Fixes #9572
Security considerations
None.
Checklist
docs/contributing/README.mdand followed the guidelines