fix: send empty object instead of null for bedrock tool input (#8121)

Signed-off-by: Extra Small <littleshuai.bot@gmail.com>
Signed-off-by: Douwe Osinga <douwe@squareup.com>
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
Extra Small
2026-03-26 07:07:37 -07:00
committed by GitHub
parent 3e1bed201c
commit 81d623709b
2 changed files with 10 additions and 3 deletions
@@ -72,7 +72,7 @@ pub fn to_bedrock_message_content(content: &MessageContent) -> Result<bedrock::C
bedrock::ToolUseBlock::builder()
.tool_use_id(tool_use_id)
.name(call.name.to_string())
.input(to_bedrock_json(&Value::from(call.arguments.clone())))
.input(to_bedrock_json(&args_to_value(call.arguments.clone())))
.build()
} else {
bedrock::ToolUseBlock::builder()
@@ -87,7 +87,7 @@ pub fn to_bedrock_message_content(content: &MessageContent) -> Result<bedrock::C
bedrock::ToolUseBlock::builder()
.tool_use_id(tool_use_id)
.name(call.name.to_string())
.input(to_bedrock_json(&Value::from(call.arguments.clone())))
.input(to_bedrock_json(&args_to_value(call.arguments.clone())))
.build()
} else {
bedrock::ToolUseBlock::builder()
@@ -226,6 +226,13 @@ pub fn to_bedrock_tool(tool: &Tool) -> Result<bedrock::Tool> {
))
}
fn args_to_value(args: Option<serde_json::Map<String, Value>>) -> Value {
match args {
Some(map) => Value::Object(map),
None => Value::Object(serde_json::Map::new()),
}
}
pub fn to_bedrock_json(value: &Value) -> Document {
match value {
Value::Null => Document::Null,