Gemini 2.0 flash thinking exp is failing for JSON Mode

Code:
generation_config = {
“temperature”: 1,
“top_p”: 0.95,
“top_k”: 64,
“max_output_tokens”: 8192,
“response_mime_type”: “application/json”,
“response_schema”: {
“type”: “object”,
“properties”: {
“is_true_statement”: {“type”: “boolean”},
“is_completely_final_answer”: {“type”: “boolean”},
“reply”: {“type”: “string”},
},
“required”: [“is_true_statement”, “is_completely_final_answer”, “reply”]
}

    model = genai.GenerativeModel(
        # model_name="gemini-1.5-flash",
        # model_name="gemini-1.5-pro",
        model_name="gemini-2.0-flash-thinking-exp-1219",
        generation_config=generation_config,
        system_instruction=system_message
    )
    if not session:
        session = model.start_chat(
            history=chat_history
        )

    parts = []
    if file_part:
        parts.append(file_part)
    parts.append(Part(text=user_chat_input))
    content = Content(role="user", parts=parts)
    gemini_response = session.send_message(content)

Error:
google.api_core.exceptions.InvalidArgument: 400 Json mode is not enabled for models/gemini-2.0-flash-thinking-exp-1219

2 Likes

Getting the same thing here

1 Like

Continuing the discussion from Gemini 2.0 flash thinking exp is failing for JSON Mode:

@Angelo_Cortez Attempt this again after ensuring your code is clean.

JSON mode is not expected to work in Gemini 2.0 flash. The limitations section of thinking mode documentation mentioned that there is no built-in tool usage, and text only output. The documentation will be updated to make it clearer.