google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

Inconsistent Response Format for Gemini Model on Vertex AI (List vs. Dictionary)

Open 952446418 opened this issue 3 months ago • 1 comments

Determine this is the right repository

  • [x] I determined this is the correct repository in which to report this bug.

Summary of the issue

Context When using the Gemini model via Vertex AI, I encountered an inconsistent response format issue during error scenarios. The response.json() method returns a list when the API encounters an error, which contradicts the expected dictionary format—this format is consistently used for successful responses. This inconsistency breaks the unified response parsing logic in my application.

Expected Behavior: Error responses should maintain the same dictionary format as successful responses.

Actual Behavior: Error responses return a list via response.json().

Failed to transform agent message: req_id: Y7WO3wN4 PluginInvokeError: {"args":{},"error_type":"Exception","message":"read llm model failed: request failed: [model_providers:large_language_model:gemini-2.0-flash-001] Error: req_id: 42eW2zZ9 PluginInvokeError: {"args":{},"error_type":"AttributeError","message":"'list' object has no attribute 'get' (model: gemini-2.0-flash-001, provider: vertex_ai)"}"}

API client name and version

google-api-core 2.26.0

Reproduction steps: code

for chunk in response: pass

(google-api_core-exceptions) def from_http_response(response): try: payload = response.json() except ValueError: payload = {"error": {"message": response.text or "unknown error"}} return format_http_response_error( response, response.request.method, response.request.url, payload )

def format_http_response_error( response, method: str, url: str, payload: Optional[Dict] = None ): """Create a :class:GoogleAPICallError from a google auth rest response.

Args:
    response Union[google.auth.transport.Response, google.auth.aio.transport.Response]: The HTTP response.
    method Optional(str): The HTTP request method.
    url Optional(str): The HTTP request url.
    payload Optional(dict): The HTTP response payload. If not passed in, it is read from response for a response type of google.auth.transport.Response.

Returns:
    GoogleAPICallError: An instance of the appropriate subclass of
        :class:`GoogleAPICallError`, with the message and errors populated
        from the response.
"""
payload = {} if not payload else payload
error_message = **payload.get**("error", {}).get("message", "unknown error")

Reproduction steps: supporting files

file: mydata.csv

alpha,1,3
beta,2,5

Reproduction steps: actual results

file: output.txtmydata.csv

Calculated: foo

Reproduction steps: expected results

file: output.txtmydata.csv

Calculated: bar

OS & version + platform

No response

Python environment

No response

Python dependencies

No response

Additional context

No response

952446418 avatar Oct 11 '25 09:10 952446418

@952446418 To help us troubleshoot the issue more, what client are you instantiating, and what client method are you calling?

gkevinzheng avatar Oct 15 '25 18:10 gkevinzheng