Skip to content

fix:toolcall return string #2885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public String convert(@Nullable Object result, @Nullable Type returnType) {
final var imgB64 = Base64.getEncoder().encodeToString(buf.toByteArray());
return JsonParser.toJson(Map.of("mimeType", "image/png", "data", imgB64));
}
else if (result instanceof String stringResult) {
Copy link
Member

@markpollack markpollack Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current assumption is that if is not a rendered image, we assume it is json (also a string) in this current PR, the json conversion in the else statement will never be accessed. Can you explain more of the surrounding use case that motivated you to make this change? adding to DefaultToolCallResultConverterTests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also wondering why JsonParser.toJson(result); doesn't use Type returnType

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any thoughts @tzolov ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current assumption is that if is not a rendered image, we assume it is json (also a string) in this current PR, the json conversion in the else statement will never be accessed. Can you explain more of the surrounding use case that motivated you to make this change? adding to DefaultToolCallResultConverterTests?

Hey, thanks for the review!
I noticed that when I use the org.springframework.ai.tool.annotation.Tool annotation and the method returns a String, the result gets escaped (see screenshot below). I’m not really sure if this is the expected behavior, or if there’s any doc about it.
If this is actually, I will to close the PR.
Thanks!

image image

logger.debug("Returning string result.");
return stringResult;
}
else {
logger.debug("Converting tool result to JSON.");
return JsonParser.toJson(result);
Expand Down