Skip to content

Commit 43d21dc

Browse files
committed
Prevent sending thinking blocks to Bedrock with no signature
1 parent 2a9f650 commit 43d21dc

File tree

2 files changed

+384
-16
lines changed

2 files changed

+384
-16
lines changed

libs/aws/langchain_aws/chat_models/bedrock_converse.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,28 +1082,30 @@ def _lc_content_to_bedrock(
10821082
elif block["type"] == "guard_content":
10831083
bedrock_content.append({"guardContent": {"text": {"text": block["text"]}}})
10841084
elif block["type"] == "thinking":
1085-
bedrock_content.append(
1086-
{
1087-
"reasoningContent": {
1088-
"reasoningText": {
1089-
"text": block.get("thinking", ""),
1090-
"signature": block.get("signature", "")
1085+
if block.get("signature", ""):
1086+
bedrock_content.append(
1087+
{
1088+
"reasoningContent": {
1089+
"reasoningText": {
1090+
"text": block.get("thinking", ""),
1091+
"signature": block.get("signature", ""),
1092+
}
10911093
}
10921094
}
1093-
}
1094-
)
1095+
)
10951096
elif block["type"] == "reasoning_content":
10961097
reasoning_content = block.get("reasoningContent", {})
1097-
bedrock_content.append(
1098-
{
1099-
"reasoningContent": {
1100-
"reasoningText": {
1101-
"text": reasoning_content.get("text", ""),
1102-
"signature": reasoning_content.get("signature", "")
1098+
if reasoning_content.get("signature", ""):
1099+
bedrock_content.append(
1100+
{
1101+
"reasoningContent": {
1102+
"reasoningText": {
1103+
"text": reasoning_content.get("text", ""),
1104+
"signature": reasoning_content.get("signature", ""),
1105+
}
11031106
}
11041107
}
1105-
}
1106-
)
1108+
)
11071109
else:
11081110
raise ValueError(f"Unsupported content block type:\n{block}")
11091111
# drop empty text blocks

0 commit comments

Comments
 (0)