Skip to content
Merged
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
52 changes: 47 additions & 5 deletions crates/goose/src/providers/formats/bedrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,10 @@ pub fn to_bedrock_message_content(content: &MessageContent) -> Result<bedrock::C
.collect::<Result<_>>()?,
),
Err(error) => {
// For errors, create a text content block with the error message
Some(vec![bedrock::ToolResultContentBlock::Text(format!(
"The tool call returned the following error:\n{}",
error
))])
let message = format!("The tool call returned the following error:\n{}", error);
Some(vec![bedrock::ToolResultContentBlock::Text(
crate::utils::sanitize_unicode_tags(&message),
)])
}
};
bedrock::ContentBlock::ToolResult(
Expand Down Expand Up @@ -1250,6 +1249,49 @@ mod tests {
Ok(())
}

#[test]
fn tool_response_error_sanitizes_unicode_tags() -> Result<()> {
let error = ErrorData::new(
ErrorCode::INTERNAL_ERROR,
"visible\u{E0041}\u{E0042} error".to_string(),
None,
);
let content = MessageContent::tool_response("call_hidden".to_string(), Err(error));

let bedrock::ContentBlock::ToolResult(result) = to_bedrock_message_content(&content)?
else {
panic!("expected ToolResult");
};
let bedrock::ToolResultContentBlock::Text(text) = &result.content[0] else {
panic!("expected text error content");
};

assert!(!crate::utils::contains_unicode_tags(text.as_str()));
assert!(text.contains("visible error"));
Ok(())
}

#[test]
fn tool_response_error_preserves_ordinary_text() -> Result<()> {
let error = ErrorData::new(
ErrorCode::INTERNAL_ERROR,
"ordinary tool failure".to_string(),
None,
);
let content = MessageContent::tool_response("call_error".to_string(), Err(error));

let bedrock::ContentBlock::ToolResult(result) = to_bedrock_message_content(&content)?
else {
panic!("expected ToolResult");
};
let bedrock::ToolResultContentBlock::Text(text) = &result.content[0] else {
panic!("expected text error content");
};

assert!(text.contains("ordinary tool failure"));
Ok(())
}

#[test]
fn test_cache_points_with_tool_response_messages() -> Result<()> {
use chrono::Utc;
Expand Down
Loading