spring-projects/spring-ai · error · java.lang.IllegalArgumentException
Tool execution results are not supported for Bedrock models
Error message
Tool execution results are not supported for Bedrock models
What it means
MessageToPromptConverter converts Spring AI Message objects into a single text prompt for Titan-style Bedrock models. Bedrock models driven through this converter only support plain text prompt completion, so a Message of type TOOL (a tool/function execution result fed back to the model) cannot be represented and is rejected. The library throws IllegalArgumentException because continuing would silently drop tool output.
Source
Thrown at models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/MessageToPromptConverter.java:91
final String userMessages = messages.stream()
.filter(message -> message.getMessageType() == MessageType.USER
|| message.getMessageType() == MessageType.ASSISTANT)
.map(this::messageToString)
.collect(Collectors.joining(System.lineSeparator()));
// Related to: https://github.com/spring-projects/spring-ai/issues/404
return systemMessages + this.lineSeparator + this.lineSeparator + userMessages + this.lineSeparator
+ ASSISTANT_PROMPT;
}
protected @Nullable String messageToString(Message message) {
return switch (message.getMessageType()) {
case SYSTEM -> message.getText();
case USER -> this.humanPrompt + " " + message.getText();
case ASSISTANT -> this.assistantPrompt + " " + message.getText();
case TOOL ->
throw new IllegalArgumentException("Tool execution results are not supported for Bedrock models");
};
}
}
View on GitHub (pinned to 98a7beda4f)
Solutions
- Do not send tool result messages to Bedrock models that lack tool support; convert the tool output into a USER or ASSISTANT text message yourself before building the Prompt
- Switch to a Bedrock model/client that supports native tool use (e.g. Anthropic Claude on Bedrock via its supported client)
- Remove ToolResponseMessage entries from the prompt or handle tool orchestration in application code instead of via the framework
Example fix
// before
Prompt prompt = new Prompt(List.of(userMsg, toolResponseMessage));
bedrockChatModel.call(prompt); // throws
// after
Message toolAsText = new UserMessage("Tool result: " + toolResponseMessage.getResponses().get(0).responseData());
Prompt prompt = new Prompt(List.of(userMsg, toolAsText)); Defensive patterns
Strategy: validation
Validate before calling
boolean hasToolMessages = prompt.getInstructions().stream().anyMatch(m -> m.getMessageType() == MessageType.TOOL);
if (hasToolMessages) throw new IllegalStateException("Bedrock model does not support TOOL messages; convert them to text first"); Type guard
boolean isToolMessage(Message m) { return m.getMessageType() == MessageType.TOOL; } Try / catch
try { model.call(prompt); } catch (IllegalArgumentException e) { if (e.getMessage().contains("Tool execution results")) { /* convert tool messages to text and retry */ } else throw e; } Prevention
- Never send ToolResponseMessage to text-completion Bedrock models
- Map tool outputs into UserMessage text manually when orchestrating tools
- Check model capability docs before enabling tool calling
When it happens
Trigger: Calling the Bedrock chat model with a Prompt whose message list contains a ToolResponseMessage / Message with MessageType TOOL, e.g. after a tool call round-trip with a model client that routes through messageToString.
Common situations: Enabling Spring AI tool/function calling with a Bedrock model (Titan) that has no native tool-calling API; reusing a prompt built for OpenAI/Anthropic (which support tool messages) against Bedrock; upgrading code to a Spring AI version where tool results are delivered as TOOL messages.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Invalid JSON format for the input request:
- Region is empty and cannot be loaded from DefaultAwsRegionPr
- The region '<region>' is not a valid region!
- Required properties for TitanEmbeddingBedrockApi are missing
- InputType property for BedrockTitanEmbeddingModel is missing
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/396513127c74ccbb.
Report an issue: GitHub.