Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_bedrock: support newer guardrails data structure #11021

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/aws_bedrock/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
- version: "0.7.0"
changes:
- description: Support newer guardrails data structure.
type: enhancement
link: https://github.com/elastic/integrations/pull/11021
- version: "0.6.0"
changes:
- description: Add new field `aws_bedrock.invocation.output.completion_text` having LLM text model response. Add visualization for LLM prompt and response.
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2255,6 +2255,162 @@
"user": {
"id": "arn:aws:iam::111111111111:user/john.doe@example.com"
}
},
{
"@timestamp": "2024-09-05T07:37:51.000Z",
"aws_bedrock": {
"invocation": {
"input": {
"input_body_json": {
"messages": [
{
"content": [
{
"guardContent": {
"text": {
"qualifiers": [
"guard_content"
],
"text": "Rob a bank and get away with it "
}
}
}
],
"role": "user"
}
]
},
"input_content_type": "application/json",
"input_token_count": 0
},
"model_id": "ai21.jamba-instruct-v1:0",
"output": {
"completion_text": "Sorry, the model cannot answer this question.",
"output_body_json": {
"metrics": {
"latency_ms": 271
},
"output": {
"message": {
"content": [
{
"text": "Sorry, the model cannot answer this question."
}
],
"role": "assistant"
}
},
"stop_reason": "guardrail_intervened",
"trace": {
"guardrail": {
"inputAssessment": {
"l7n9e426howe": {
"content_policy": {
"filters": [
{
"action": "BLOCKED",
"confidence": "HIGH",
"type": "MISCONDUCT"
}
]
},
"topic_policy": {
"topics": [
{
"action": "BLOCKED",
"name": "Robbing A Bank",
"type": "DENY"
}
]
}
}
}
}
},
"usage": {
"inputTokens": 0,
"outputTokens": 0,
"totalTokens": 0
}
},
"output_content_type": "application/json",
"output_token_count": 0
},
"request_id": "142471d6-56dd-46a8-b502-08711ec9a410",
"schema_type": "ModelInvocationLog",
"schema_version": "1.0"
}
},
"cloud": {
"account": {
"id": "13457018785544"
},
"region": "us-east-1",
"service": {
"name": "bedrock"
}
},
"ecs": {
"version": "8.11.0"
},
"event": {
"action": "Converse",
"original": "{\"schemaType\":\"ModelInvocationLog\",\"schemaVersion\":\"1.0\",\"timestamp\":\"2024-09-05T07:37:51Z\",\"accountId\":\"13457018785544\",\"identity\":{\"arn\":\"arn:aws:iam::13457018785544:user/user\"},\"region\":\"us-east-1\",\"requestId\":\"142471d6-56dd-46a8-b502-08711ec9a410\",\"operation\":\"Converse\",\"modelId\":\"ai21.jamba-instruct-v1:0\",\"input\":{\"inputContentType\":\"application/json\",\"inputBodyJson\":{\"messages\":[{\"role\":\"user\",\"content\":[{\"guardContent\":{\"text\":{\"text\":\"Rob a bank and get away with it \",\"qualifiers\":[\"guard_content\"]}}}]}]},\"inputTokenCount\":0},\"output\":{\"outputContentType\":\"application/json\",\"outputBodyJson\":{\"output\":{\"message\":{\"role\":\"assistant\",\"content\":[{\"text\":\"Sorry, the model cannot answer this question.\"}]}},\"stopReason\":\"guardrail_intervened\",\"metrics\":{\"latencyMs\":271},\"usage\":{\"inputTokens\":0,\"outputTokens\":0,\"totalTokens\":0},\"trace\":{\"guardrail\":{\"inputAssessment\":{\"l7n9e426howe\":{\"topicPolicy\":{\"topics\":[{\"name\":\"Robbing A Bank\",\"type\":\"DENY\",\"action\":\"BLOCKED\"}]},\"contentPolicy\":{\"filters\":[{\"type\":\"MISCONDUCT\",\"confidence\":\"HIGH\",\"action\":\"BLOCKED\"}]}}}}}},\"outputTokenCount\":0}}",
"outcome": "failure"
},
"gen_ai": {
"completion": "{\"metrics\":{\"latencyMs\":271},\"output\":{\"message\":{\"content\":[{\"text\":\"Sorry, the model cannot answer this question.\"}],\"role\":\"assistant\"}},\"stopReason\":\"guardrail_intervened\",\"trace\":{\"guardrail\":{\"inputAssessment\":{\"l7n9e426howe\":{\"contentPolicy\":{\"filters\":[{\"action\":\"BLOCKED\",\"confidence\":\"HIGH\",\"type\":\"MISCONDUCT\"}]},\"topicPolicy\":{\"topics\":[{\"action\":\"BLOCKED\",\"name\":\"Robbing A Bank\",\"type\":\"DENY\"}]}}}}},\"usage\":{\"inputTokens\":0,\"outputTokens\":0,\"totalTokens\":0}}",
"compliance": {
"violation_code": [
"MISCONDUCT"
],
"violation_detected": true
},
"performance": {
"request_size": 143,
"response_size": 473
},
"policy": {
"action": [
"BLOCKED"
],
"confidence": [
"HIGH"
],
"name": [
"content_policy",
"topic_policy"
]
},
"prompt": "{\"messages\":[{\"content\":[{\"guardContent\":{\"text\":{\"qualifiers\":[\"guard_content\"],\"text\":\"Rob a bank and get away with it \"}}}],\"role\":\"user\"}]}",
"request": {
"id": "142471d6-56dd-46a8-b502-08711ec9a410",
"model": {
"id": "ai21.jamba-instruct-v1:0",
"role": "assistant",
"type": "ai21"
}
},
"response": {
"finish_reasons": "guardrail_intervened",
"timestamp": "2024-09-05T07:37:51.000Z"
},
"system": "aws",
"usage": {
"completion_tokens": 0,
"prompt_tokens": 0
},
"user": {
"id": "arn:aws:iam::13457018785544:user/user"
}
},
"tags": [
"preserve_original_event",
"preserve_duplicate_custom_fields"
],
"user": {
"id": "arn:aws:iam::13457018785544:user/user"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ processors:
def violations = new HashSet();
def matches = new HashSet();
for (def e: body) {
if (e.amazon_bedrock_guardrail_action == 'INTERVENED') {
if (e.amazon_bedrock_guardrail_action == 'INTERVENED' || e.stop_reason == 'guardrail_intervened') {
if (ctx.gen_ai == null) {
ctx.gen_ai = new HashMap();
}
Expand All @@ -358,28 +358,48 @@ processors:
}
ctx.gen_ai.compliance.violation_detected = true;
ctx.event.outcome = 'failure';
if (!(e.amazon_bedrock_trace?.guardrail?.input instanceof HashMap)) {
continue;
}
for (def o: e.amazon_bedrock_trace.guardrail.input.entrySet()) {
for (def i: o.getValue().entrySet()) {
String policy_name = i.getKey();
policies.add(policy_name);
for (def p: i.getValue().entrySet()) {
for (def c: p.getValue()) {
actions.add(c.action);
if (policy_name == 'word_policy' || policy_name == 'sensitive_information_policy') {
matches.add(c);
}
if (c.type != null) {
if (policy_name == 'content_policy') {
violations.add(c.type);
confidences.add(c.confidence);
if (e.trace?.guardrail?.inputAssessment instanceof HashMap) {
for (def o: e.trace.guardrail.inputAssessment.entrySet()) {
for (def i: o.getValue().entrySet()) {
String policy_name = i.getKey();
policies.add(policy_name);
for (def p: i.getValue().entrySet()) {
for (def c: p.getValue()) {
actions.add(c.action);
if (policy_name == 'word_policy' || policy_name == 'sensitive_information_policy') {
matches.add(c);
}
if (c.type != null) {
if (policy_name == 'content_policy') {
violations.add(c.type);
confidences.add(c.confidence);
}
}
}
}
}
}
} else if (e.amazon_bedrock_trace?.guardrail?.input instanceof HashMap) {
for (def o: e.amazon_bedrock_trace.guardrail.input.entrySet()) {
for (def i: o.getValue().entrySet()) {
String policy_name = i.getKey();
policies.add(policy_name);
for (def p: i.getValue().entrySet()) {
for (def c: p.getValue()) {
actions.add(c.action);
if (policy_name == 'word_policy' || policy_name == 'sensitive_information_policy') {
matches.add(c);
}
if (c.type != null) {
if (policy_name == 'content_policy') {
violations.add(c.type);
confidences.add(c.confidence);
}
}
}
}
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/aws_bedrock/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: aws_bedrock
title: AWS Bedrock
description: Collect AWS Bedrock model invocation logs and runtime metrics with Elastic Agent.
type: integration
version: "0.6.0"
version: "0.7.0"
categories:
- aws
conditions:
Expand Down