refactor(bedrock): replace apply_guardrail temp clone with a borrowed view#345
Merged
vieiralucas merged 1 commit intomainfrom Apr 13, 2026
Merged
Conversation
… view apply_guardrail used to synthesize a full Guardrail by field-cloning 13 values off either the DRAFT entry or a GuardrailVersion, only to read the policy config + blocked messaging back out. Introduce GuardrailView<'a>, a borrowed projection over the subset of fields content evaluation actually touches, and drop the 13-field clone in favor of GuardrailView::from_guardrail / from_version. evaluate_content delegates to a new evaluate_content_view that operates on the view.
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
`apply_guardrail` used to build a temporary `Guardrail` by field-cloning 13 values off either the DRAFT entry or a `GuardrailVersion`, only so that `evaluate_content` and the blocked-messaging fallback could read them back. Replace that with `GuardrailView<'a>`, a borrowed projection over the subset of fields the evaluator actually needs (`word_policy`, `topic_policy`, `sensitive_information_policy`, `blocked_input_messaging`, `blocked_outputs_messaging`).
Other clone audit notes
StepFunctions `interpreter.rs`, SecretsManager, and CloudFormation clone audits will be separate PRs.
Test plan
Summary by cubic
Replaced the temporary cloned
Guardrailinapply_guardrailwith a borrowedGuardrailView<'a>for content evaluation. This removes 13 field clones, reduces allocations, and keeps the public API and behavior unchanged.GuardrailViewwithword_policy,topic_policy,sensitive_information_policy,blocked_input_messaging,blocked_outputs_messaging.GuardrailView::from_guardrailandGuardrailView::from_version.evaluate_content_view;evaluate_content(&Guardrail)now delegates to it.apply_guardrailto build a view (DRAFT or versioned) and read blocked messaging directly from it.Written for commit 5634d5e. Summary will update on new commits.