From ebe192168c122adf696c3def3cdb83aa7df38f3a Mon Sep 17 00:00:00 2001 From: Cole Crawford Date: Fri, 4 Sep 2026 18:31:53 -0400 Subject: [PATCH] fix(llmobs): read the text of Bedrock Converse guardContent blocks A guardContent block scopes a Bedrock guardrail to part of a Converse turn, usually the user question. The LLM Observability walker treated it as an unsupported block and recorded a placeholder, so the llm span kept the surrounding context and lost the question. Read guardContent.text.text like a plain text block. Input-only block, so response and stream extraction are unchanged. Fixes #10172 --- .../src/services/bedrockruntime/utils.js | 2 ++ .../test/bedrockruntime.util.spec.js | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js index cdbec6e0b6c..1becf101ca2 100644 --- a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +++ b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js @@ -500,6 +500,8 @@ function extractMessagesFromConverseContent (role, contentBlocks) { if (block == null || typeof block !== 'object') continue if (typeof block.text === 'string') { content += block.text + } else if (typeof block.guardContent?.text?.text === 'string') { + content += block.guardContent.text.text } else if (block.toolUse) { toolCalls.push(buildToolCall(block.toolUse)) } else if (block.toolResult) { diff --git a/packages/datadog-plugin-aws-sdk/test/bedrockruntime.util.spec.js b/packages/datadog-plugin-aws-sdk/test/bedrockruntime.util.spec.js index 77a58d9ca15..77a7f7dbe07 100644 --- a/packages/datadog-plugin-aws-sdk/test/bedrockruntime.util.spec.js +++ b/packages/datadog-plugin-aws-sdk/test/bedrockruntime.util.spec.js @@ -73,6 +73,19 @@ describe('bedrockruntime utils', () => { }) }) + it('reads the text of Converse guardContent blocks', () => { + const message = extractMessagesFromConverseContent('user', [ + { text: 'Context: ' }, + { guardContent: { text: { text: 'What is the dose?', qualifiers: ['guard_content'] } } }, + { text: ' Cite sources.' }, + ]) + + assert.deepStrictEqual(message, { + role: 'user', + content: 'Context: What is the dose? Cite sources.', + }) + }) + describe('converse stream extractor', () => { it('returns an empty message when the stream fails before yielding a chunk', () => { const generation = extractTextAndResponseReasonConverseFromStream()