← Back to Pull requests

fix: bedrock converse-stream reports a guardrail block as guardrail_intervened #10036

Open
unknown opened this pull request with 490 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 14, 2026 12:31 UTC
Author

Summary

When a Bedrock guardrail blocks a turn, /bedrock/model/{modelId}/converse-stream ended the stream with messageStop.stopReason: "content_filtered". Bedrock ConverseStream sends "guardrail_intervened", and non-streaming /converse already returns that.

FinalizeBedrockStream maps both guardrail_intervened and content_filter to the same IncompleteDetails{Reason: "content_filter"} and keeps the original value on StopReason. The ToBedrockConverseStreamResponse terminal arm lets recognized incomplete details win over StopReason, so both come out as content_filtered. restoreBedrockNativeStopReason only acts on end_turn, so it doesn't undo this.

Changes

  • core/providers/bedrock/responses.go: in the converse-stream terminal arm, when the details map to content_filtered and the explicit stop reason is guardrail_intervened, keep guardrail_intervened. Everything else keeps the current order. That covers an Anthropic refusal and a model content_filter, which both stay content_filtered, and max_output_tokens details, which still give max_tokens.

  • core/providers/bedrock/conversestreamstop_test.go: TestConverseStreamGuardrailStopReason.

  • tests/e2e/api/collections/provider-harness.json: folder 390, a /converse control case and the /converse-stream case, both using the same blocked prompt and guardrailConfig as 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

  • Bug fix

  • Feature

  • Refactor

  • Documentation

  • Chore/CI
  • Affected areas

  • Core (Go)

  • Transports (HTTP)

  • Providers/Integrations

  • Plugins

  • UI (React)

  • Docs
  • How to test

    cd core
    go test -count=1 -run TestConverseStreamGuardrailStopReason -v ./providers/bedrock/
    go test -count=1 ./providers/bedrock/...
    

    TestConverseStreamGuardrailStopReason replays a ConverseStream answer ending in guardrail_intervened, content_filtered and max_tokens through the upstream converter, FinalizeBedrockStream and 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"}, and guardrail_intervened plus content_filter details give content_filtered.

  • this PR: PASS. The content_filtered, content_filter, max_tokens and no-details cases are unchanged.
  • go vet and gofmt are clean, and golangci-lint reports 0 issues on the change.

    Harness: folder 390 passes augment-provider-harness.mjs and filter-collection.mjs --provider bedrock --feature "guardrail stop reason" keeps both cases. The /converse-stream case should be red on dev and green here. I didn't run it live:

    make dev PORT=8091 APP_DIR=$(pwd)/tests/integrations/python
    make run-provider-harness-test PROVIDER=bedrock FEATURE="guardrail stop reason" BASE_URL=http://localhost:8091
    

    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

  • Yes

  • No
  • Related issues

    Fixes #9572

    Security considerations

    None.

    Checklist

  • I read docs/contributing/README.md and followed the guidelines

  • I added/updated tests where appropriate

  • I updated documentation where needed

  • I verified builds succeed (Go and UI)

  • I verified the CI pipeline passes locally if applicable
  • Diff: 490 lines (+367 / -123) across 6 files Reviewer: mansur-akhmadi Review duration: 24335m
    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
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.4% (MEDIUM) · Higher = larger blast radius
    47.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.3% · Safe to merge
    25.3%