aws_bedrock: retain contextualGroundingPolicy check details#11890
aws_bedrock: retain contextualGroundingPolicy check details#11890efd6 merged 0 commit intoelastic:mainfrom
Conversation
42c9b10 to
be801ec
Compare
|
Pinging @elastic/security-service-integrations (Team:Security-Service Integrations) |
shashank-elastic
left a comment
There was a problem hiding this comment.
Filed mapping correction looks good
chrisberkhout
left a comment
There was a problem hiding this comment.
It looks like we should be looking at body.trace.guardrail.outputAssessments in general, since we are looking at body.amazon_bedrock_trace.guardrail.outputs. I probably should have done that in my last change, which started looking at outputs.
If that's added, then the other change is to expand which details objects get added to gen_ai.policy.match_detail.
What do you think about this version? The test output is slightly different.
--- a/packages/aws_bedrock/data_stream/invocation/elasticsearch/ingest_pipeline/default.yml
+++ b/packages/aws_bedrock/data_stream/invocation/elasticsearch/ingest_pipeline/default.yml
@@ -170,6 +170,7 @@ processors:
"topicPolicy": "topic_policy"
"customWords": "custom_words"
"sensitiveInformationPolicy": "sensitive_information_policy"
+ "contextualGroundingPolicy": "contextual_grounding_policy"
"invocationMetrics": "invocation_metrics"
"guardrailCoverage": "guardrail_coverage"
"textCharacters": "text_characters"
@@ -356,6 +357,7 @@ processors:
)
.flatMap(body -> [
[body.trace?.guardrail?.inputAssessment],
+ body.trace?.guardrail?.outputAssessments,
[body.amazon_bedrock_trace?.guardrail?.input],
body.amazon_bedrock_trace?.guardrail?.outputs
].stream())
@@ -404,7 +406,7 @@ processors:
.collect(Collectors.toList());
ctx.gen_ai.policy.match_detail = nameAndDetailsOfPolicies.stream()
- .filter(policy -> policy.details.match != null)
+ .filter(policy -> policy.details.match != null || policy.name == 'contextual_grounding_policy')
.map(policy -> policy.details)
.distinct() // no sort because HashMap isn't Comparable
.collect(Collectors.toList());be801ec to
5525432
Compare
|
Yeah, I think that's good. The changes that I see in the test expectation actually fix concerns that I had with the current behaviour, so that is nice. Will wait for @shashank-elastic's input though. |
🚀 Benchmarks reportTo see the full report comment with |
@efd6 The filed mapping for outputassesments for contextualGroundingPolicy look good! |
There was a problem hiding this comment.
My diff was on main version of this file, so this part would just be:
| ctx.gen_ai.policy.match_detail = Stream.concat( | |
| nameAndDetailsOfPolicies.stream() | |
| .filter(policy -> policy.details.match != null || policy.name == 'contextual_grounding_policy') | |
| .map(policy -> policy.details), | |
| allBodies.stream() | |
| .filter(body -> body.trace?.guardrail?.outputAssessments instanceof List) | |
| .flatMap(body -> body.trace.guardrail.outputAssessments.stream()) | |
| .filter(output -> output instanceof HashMap) | |
| .flatMap(output -> output.entrySet().stream()) | |
| .map(assessment -> assessment.getValue()) | |
| .filter(details -> details.contextualGroundingPolicy?.filters instanceof List) | |
| .flatMap(details -> details.contextualGroundingPolicy.filters.stream()) | |
| ) | |
| .distinct() // no sort because HashMap isn't Comparable | |
| .collect(Collectors.toList()); | |
| ctx.gen_ai.policy.match_detail = nameAndDetailsOfPolicies.stream() | |
| .filter(policy -> policy.details.match != null || policy.name == 'contextual_grounding_policy') | |
| .map(policy -> policy.details) | |
| .distinct() // no sort because HashMap isn't Comparable | |
| .collect(Collectors.toList()); |
Currently the 2nd part of the concat generates nothing because it uses the camel case name contextualGroundingPolicy.
There was a problem hiding this comment.
Thanks for clarifying, I missed that. Much nicer.
💚 Build Succeeded
History
cc @efd6 |
|
|
Package aws_bedrock - 0.15.0 containing this change is available at https://epr.elastic.co/package/aws_bedrock/0.15.0/ |




Proposed commit message
See title.
Checklist
changelog.ymlfile.Author's Checklist
How to test this PR locally
Related issues
Screenshots