fix: normalize roles to system for bedrock and vertex LLM providers

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-14 13:44:12 -03:00
parent f04745ae1c
commit d6527a438b
2 changed files with 14 additions and 2 deletions

View file

@ -59,7 +59,17 @@ impl BedrockClient {
let mut messages_limited = Vec::new();
if let Some(msg_array) = raw_messages.as_array() {
for msg in msg_array {
messages_limited.push(msg.clone());
let role = msg.get("role").and_then(|r| r.as_str()).unwrap_or("user");
let normalized_role = match role {
"user" | "assistant" | "system" | "developer" | "tool" => role,
"episodic" | "compact" => "system",
_ => "user",
};
let mut new_msg = msg.clone();
if let Some(obj) = new_msg.as_object_mut() {
obj.insert("role".to_string(), serde_json::json!(normalized_role));
}
messages_limited.push(new_msg);
}
}
Value::Array(messages_limited)

View file

@ -231,8 +231,10 @@ impl VertexClient {
let content = msg.get("content").and_then(|c| c.as_str()).unwrap_or("");
let gemini_role = match role {
"user" => "user",
"assistant" => "model",
"system" => "user", // Gemini doesn't have system role in 'contents' by default, often wrapped in systemInstruction
"system" | "episodic" | "compact" => "user",
"tool" => "user",
_ => "user",
};