Skip to content

fix(bedrock): guardrail config dropped on retry - #7087

Draft
kohlivrinda wants to merge 1 commit into
devfrom
09-11-fix_bedrock_guardrail_config_dropped_on_retry
Draft

fix(bedrock): guardrail config dropped on retry#7087
kohlivrinda wants to merge 1 commit into
devfrom
09-11-fix_bedrock_guardrail_config_dropped_on_retry

Conversation

@kohlivrinda

@kohlivrinda kohlivrinda commented Sep 11, 2026

Copy link
Copy Markdown
Member

Summary

When applyBedrockExtraParams promotes keys like guardrailConfig to typed fields on the Bedrock request, it deletes those keys from the map. Because the converter was aliasing bifrostReq.Params.ExtraParams directly rather than copying it, those deletes mutated the caller's original request. Since core re-runs the converter on every retry and fallback attempt against the same BifrostChatRequest, any subsequent attempt saw no guardrailConfig and reached Bedrock silently unguarded — with no error raised anywhere.

Changes

  • convertChatParameters in utils.go now clones bifrostReq.Params.ExtraParams via maps.Clone before assigning it to bedrockReq.ExtraParams, preventing applyBedrockExtraParams from mutating the caller's map.
  • ToBedrockResponsesRequest in responses.go applies the same clone for the same reason, since it also deletes keys (e.g. stop) from the extra params map.
  • A regression test TestGuardrailConfigSurvivesReconversion is added covering both the chat completion and responses paths, asserting that the caller's ExtraParams map is untouched after conversion and that a simulated retry produces a request with the guardrail still attached.

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

go test ./core/providers/bedrock/... -run TestGuardrailConfigSurvivesReconversion -v

The test simulates two consecutive conversions of the same BifrostChatRequest and BifrostResponsesRequest (as core does on retry), asserting that guardrailConfig is present on both the first and second converted requests, and that the original ExtraParams map is not modified.

Screenshots/Recordings

N/A

Breaking changes

  • Yes
  • No

Related issues

N/A

Security considerations

Without this fix, guardrails configured via guardrailConfig in ExtraParams were silently dropped on any retry or fallback attempt, meaning requests could reach Bedrock without the intended guardrail applied. This fix ensures guardrails are consistently enforced across all attempts.

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

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Comment @coderabbitai help to get the list of available commands.

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@kohlivrinda
kohlivrinda force-pushed the 09-11-fix_bedrock_guardrail_config_dropped_on_retry branch from 75bf5cf to 1b30c06 Compare September 11, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant