Skip to content

Empty response for Gemini-2.5 Pro version when max_tokens is set. #811

Description

@AnanyaRaval

Environment details

  • Programming language: Python
  • OS: iOS
  • Language runtime version: 3.10.11
  • Package version: 1.14.0

Steps to reproduce

Code skeleton:

#Create input bytes from an image:
image_part = types.Part.from_bytes(
                    data=image_bytes,
                    mime_type='image/jpeg',
        )

#Create input from text prompt
messages = types.Content(
                role="user",
                parts=[
                    types.Part.from_text(text=user_prompt), #user prompt is defined earlier
                    image_part,
                ]
        )

#Create content config
generate_content_config = types.GenerateContentConfig(
                temperature = 0.0,
                max_output_tokens = 256,
                response_modalities = ["TEXT"],
                safety_settings = [...]

#Send request to Gemini-2.5 pro
full_response = client.models.generate_content(model="gemini-2.5-pro-preview-05-06",
                    contents=messages,
                    config=generate_content_config)

Error

Clipped output with empty responsetext='' and finish_reason=<FinishReason.MAX_TOKENS: 'MAX_TOKENS

:
INFO:google_genai.models:AFC is enabled with max remote calls: 10.
INFO:httpx:HTTP Request: POST https://us-central1-aiplatform.googleapis.com/v1beta1/projects/news-media-bias-plus/locations/us-central1/publishers/google/models/gemini-2.5-flash-preview-04-17:generateContent "HTTP/1.1 200 OK"
INFO:google_genai.models:AFC remote call 1 is done.
INFO:google_genai.models:AFC is enabled with max remote calls: 10.
INFO:httpx:HTTP Request: POST https://us-central1-aiplatform.googleapis.com/v1beta1/projects/news-media-bias-plus/locations/us-central1/publishers/google/models/gemini-2.5-flash-preview-04-17:generateContent "HTTP/1.1 200 OK"
INFO:google_genai.models:AFC remote call 1 is done.
INFO:google_genai.models:AFC is enabled with max remote calls: 10.
INFO:httpx:HTTP Request: POST https://us-central1-aiplatform.googleapis.com/v1beta1/projects/news-media-bias-plus/locations/us-central1/publishers/google/models/gemini-2.5-flash-preview-04-17:generateContent "HTTP/1.1 200 OK"
INFO:google_genai.models:AFC remote call 1 is done.
INFO:__main__:answer
GenerateContentResponse(candidates=[Candidate(content=Content(parts=[Part(video_metadata=None, thought=None, code_execution_result=None, executable_code=None, file_data=None, function_call=None, function_response=None, inline_data=None, text='')], role='model'), 
citation_metadata=None, finish_message=None, token_count=None, finish_reason=<FinishReason.MAX_TOKENS: 'MAX_TOKENS'>, avg_logprobs=None, grounding_metadata=None, index=None, logprobs_result=None, 
safety_ratings=[SafetyRating(blocked=None, category=<HarmCategory.HARM_CATEGORY_HATE_SPEECH: 'HARM_CATEGORY_HATE_SPEECH'>, probability=<HarmProbability.NEGLIGIBLE: 'NEGLIGIBLE'>, probability_score=0.00026749301, severity=<HarmSeverity.HARM_SEVERITY_NEGLIGIBLE: 'HARM_SEVERITY_NEGLIGIBLE'>, severity_score=0.061262906), SafetyRating(blocked=None, category=<HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: 'HARM_CATEGORY_DANGEROUS_CONTENT'>, probability=<HarmProbability.NEGLIGIBLE: 'NEGLIGIBLE'>, probability_score=2.6117214e-05, severity=<HarmSeverity.HARM_SEVERITY_NEGLIGIBLE: 'HARM_SEVERITY_NEGLIGIBLE'>, severity_score=0.03416191), SafetyRating(blocked=None, category=<HarmCategory.HARM_CATEGORY_HARASSMENT: 'HARM_CATEGORY_HARASSMENT'>, probability=<HarmProbability.NEGLIGIBLE: 'NEGLIGIBLE'>, probability_score=1.2193676e-05, severity=<HarmSeverity.HARM_SEVERITY_NEGLIGIBLE: 'HARM_SEVERITY_NEGLIGIBLE'>, severity_score=0.12080276), SafetyRating(blocked=None, category=<HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: 'HARM_CATEGORY_SEXUALLY_EXPLICIT'>, probability=<HarmProbability.NEGLIGIBLE: 'NEGLIGIBLE'>, probability_score=7.057463e-05, severity=<HarmSeverity.HARM_SEVERITY_NEGLIGIBLE: 'HARM_SEVERITY_NEGLIGIBLE'>, severity_score=0.11359745)])], create_time=datetime.datetime(2025, 5, 13, 15, 8, 21, 868816, tzinfo=TzInfo(UTC)), response_id='ZWAjaNCDNcW2ld8PgO-QmQc', 
model_version='gemini-2.5-flash-preview-04-17', prompt_feedback=None, 
usage_metadata=GenerateContentResponseUsageMetadata(cache_tokens_details=None, cached_content_token_count=None, candidates_token_count=None, candidates_tokens_details=None, prompt_token_count=336, prompt_tokens_details=[ModalityTokenCount(modality=<MediaModality.TEXT: 'TEXT'>, token_count=78), 
ModalityTokenCount(modality=<MediaModality.IMAGE: 'IMAGE'>, token_count=258)], thoughts_token_count=256, tool_use_prompt_token_count=None, tool_use_prompt_tokens_details=None, total_token_count=592, traffic_type=<TrafficType.ON_DEMAND: 'ON_DEMAND'>), automatic_function_calling_history=[], parsed=None)

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p2Moderately-important priority. Fix may not be included in next release.type: questionRequest for information or clarification. Not an issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions