Skip to content

Commit 652148d

Browse files
authored
fix: handles tool validation errors (#651)
1 parent 0cb2339 commit 652148d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

crates/q_cli/src/cli/chat/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,29 @@ Hi, I'm <g>Amazon Q</g>. I can answer questions about your workspace and tooling
468468
// If we have any validation errors, then return them immediately to the model.
469469
if !tool_results.is_empty() {
470470
debug!(?tool_results, "Error found in the model tools");
471+
queue!(
472+
self.output,
473+
style::SetAttribute(Attribute::Bold),
474+
style::Print("Tool validation failed: "),
475+
style::SetAttribute(Attribute::Reset),
476+
)?;
477+
for tool_result in &tool_results {
478+
for block in &tool_result.content {
479+
let content = match block {
480+
ToolResultContentBlock::Text(t) => Some(t.as_str()),
481+
ToolResultContentBlock::Json(d) => d.as_string(),
482+
};
483+
if let Some(content) = content {
484+
queue!(
485+
self.output,
486+
style::Print("\n"),
487+
style::SetForegroundColor(Color::Red),
488+
style::Print(format!("{}\n", content)),
489+
style::SetForegroundColor(Color::Reset),
490+
)?;
491+
}
492+
}
493+
}
471494
self.conversation_state.add_tool_results(tool_results);
472495
self.send_tool_use_telemetry().await;
473496
return Ok(Some(

crates/q_cli/src/cli/chat/tools/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl TryFrom<ToolUse> for Tool {
8383
let map_err = |parse_error| ToolResult {
8484
tool_use_id: value.id.clone(),
8585
content: vec![ToolResultContentBlock::Text(format!(
86-
"failed to deserialize with the following error: {parse_error}"
86+
"Failed to validate tool parameters: {parse_error}. The model has either suggested tool parameters which are incompatible with the existing tools, or has suggested one or more tool that does not exist in the list of known tools."
8787
))],
8888
status: ToolResultStatus::Error,
8989
};

0 commit comments

Comments
 (0)