Fix input/output message not redacted when guardrails_trace="enabled_full" #1072
+115
−15
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.
Description
With
guardrails_trace="enabled_full"
andguardrails_trace="disabled"
, even if guardrail_redact_input or guardrail_redact_output are True, the input/output are not redacted.See #1075 for details
This PR fixes the case with
guardrails_trace="enabled_full"
.The method
_find_detected_and_blocked_policy
failed to correctly identify the detected and blocked policies.The issue is that with
guardrails_trace="enabled_full"
, the response by Bedrock contains both triggered and non-triggered filters.The previous implementation of
_find_detected_and_blocked_policy
was bugged as it would not scan all dicts in a list, but would immediately return False after finding the first non-triggered filter.This PR fixes it making sure to return False only if none of the filter is acutally triggered. The main fix is adding the
any()
, then it also simplifies a little the implementation.Note that for the case with
guardrails_trace="disabled"
, no metadata about the guardrails is received, so the current implementation cannot know if the input/output message should be redacted.So it can't be easily fixed. Probably the use of
guardrails_trace="disabled"
should be disallowed in BedrockModel init, or at least the user should be warned against it.Related Issues
#1075
Documentation PR
No doc change needed for this PR as it is, however if the parameter guardrails_trace stops begin exposed or "disabled" is not supported, it would probably need to be updated.
Type of Change
Bug fix
Testing
Ran unit tests & integration tests.
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.