adk-java icon indicating copy to clipboard operation
adk-java copied to clipboard

Impossible to pass an image in the Dev UI with GDM/Google AI Gemini

Open glaforge opened this issue 1 year ago • 5 comments

When using the non-Vertex AI Gemini (ie. Google AI / GDM Gemini), passing an image along the prompt in the Dev UI will trigger an exception.

Example prompt: a text and a picture Image

In the console where I run the Dev UI, I'm seeing the following stacktrace:

java.lang.IllegalArgumentException: displayName parameter is not supported in Gemini API.
        at com.google.genai.Models.blobToMldev(Models.java:123) ~[google-genai-1.8.0.jar:1.8.0]
        at com.google.genai.Models.partToMldev(Models.java:191) ~[google-genai-1.8.0.jar:1.8.0]
        at com.google.genai.Models.contentToMldev(Models.java:261) ~[google-genai-1.8.0.jar:1.8.0]
        at com.google.genai.Models.generateContentParametersToMldev(Models.java:1203) ~[google-genai-1.8.0.jar:1.8.0]
        at com.google.genai.Models.privateGenerateContent(Models.java:5858) ~[google-genai-1.8.0.jar:1.8.0]
        at com.google.genai.Models.generateContent(Models.java:6750) ~[google-genai-1.8.0.jar:1.8.0]
        at com.google.genai.AsyncModels.lambda$generateContent$8(AsyncModels.java:188) ~[google-genai-1.8.0.jar:1.8.0]
        at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1814) ~[na:na]
        at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1806) ~[na:na]
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507) ~[na:na]
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1394) ~[na:na]
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1970) ~[na:na]
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187) ~[na:na]

I tried with ADK 0.2.0 as well as against what's currently on main on GitHub. Both version exhibit the same behavior. Even the simplest agent without any tool or anything will trigger this exception.

The only reference I could find of someone hitting a similar issue is this one on the GenAI SDK for Java: https://github.com/googleapis/js-genai/issues/641

It seems to hint at the fact that with Vertex AI Gemini, it's possible for blobs to have a displayName (which is probably the name of the file?) but this is not supported in the Google AI/GDM flavor of Gemini.

glaforge avatar Jul 19 '25 15:07 glaforge

I tried with ADK from the main branch, even upgrading the GenAI SDK to version 1.9.0 which is the last version (we're currently using 1.8.0), but the same error is triggered when passing a picture.

In AdkWebServer, I tried commenting lines 1723-1725 which was setting the displayName property on the blob node, but it doesn't seem to help. So the problem is probably elsewhere.

glaforge avatar Jul 19 '25 15:07 glaforge

Seems like this is worth reporting on the GenAI SDK repo right? On the ADK side, we can update the Gemini.java to remove the property https://github.com/google/adk-java/blob/1071f1e12b916e90efb22a07318a9d356b897a7c/core/src/main/java/com/google/adk/models/Gemini.java#L219

by modifying the llmRequest based on the apiClient.vertexAI() property

Poggecci avatar Jul 22 '25 16:07 Poggecci

The issue has a commit 0ebba95

A review indicates that:

  1. No Tests are provided The main branch has comprehensive tests in GeminiUtilTest.java

  2. Labels Set to null Instead of Empty Map The commit sets labels(null) which could cause NPE downstream if code expects a non-null value. The main branch correctly uses labels(ImmutableMap.of()).

  3. Method Placement The commit places sanitizeRequest() as a private method in Gemini.java. The main branch correctly extracts it to GeminiUtil as a package-visible static method, making it testable independently and following the existing utility pattern.

To be considered as part of a PR, it needs:

  • Unit tests for sanitizeRequest() covering inlineData, fileData, labels, and edge cases
  • Fix the labels(null) to labels(ImmutableMap.of())
  • Consider extracting to GeminiUtil for testability

ddobrin avatar Mar 18 '26 20:03 ddobrin

Hi! Just following up on this — this issue was fixed previously with request sanitization in GeminiUtil.sanitizeRequestForGeminiApi(), which automatically strips displayName from image/blob payloads when using Google AI / GDM Gemini. I tested this with the latest build and wasn't able to reproduce the error; passing images in the Dev UI works as expected now.

kvmilos avatar Jul 21 '26 12:07 kvmilos

Thank you very much!

glaforge avatar Jul 21 '26 13:07 glaforge