Unexpected Response : Gemini 2.5 flash always reponse a specific article(or system prompt maybe) only at first request

hi recently i make an android app with Android Studio (Kotlin)

and i always found that Gemini always response a specific article type text only at first request.

Gemini ignore what i instructed that use my output format. But every first response, it ignored.

even i used hanguel(korean) when input prompt!

here is that response.


You are a highly specialized Python code generation AI. Your primary function is to generate Python code based on user requests.
                                                                                                    
                                                                                                    However, you operate under a strict, non-negotiable output protocol:
                                                                                                    
                                                                                                    1.  **Successful Code Generation:**
                                                                                                        *   When you successfully generate Python code, your *entire* output must consist of two parts, in this exact order:
                                                                                                            *   The phrase: `Here is your Python code:` (followed by a newline).
                                                                                                            *   A standard markdown code block containing the generated Python code.
                                                                                                        *   No other text, explanations, conversational elements, or preamble/postamble is permitted.
                                                                                                    
                                                                                                    2.  **Unfulfillable Request:**
                                                                                                        *   If a user's request is unclear, ambiguous, impossible to fulfill, or outside the scope of Python code generation, your *entire* output must be the single phrase: `I cannot fulfill this request.`
                                                                                                    
                                                                                                    Adhere to these instructions precisely for every interaction.

i test everytime in virtual device (in Android studio).

here is my environment.

  • gemini 2.5 flash
  • temperature = 0.0f
  • top-k = 1
  • virtual device in Android Studio

and also another type, itโ€™s seems like a article like below image.

(plz start with โ€œUsing Artificial Intelโ€ฆ..โ€)

in addition, one time, i changed temperature 0.2, and then Gemini responsed another article type text.

what should i do? is it realted hallucination? or a safety policy? thank you.

Hi @Kim143,

You mentioned that the responses you are receiving are inconsistent and irrelevant to the requested topic. Is this issue occurring exclusively with Gemini 2.5?

We recommend trying Gemini 3.0, which is currently our most advanced model. If you have already tried other models and are still encountering the same behavior, could you please share a snippet of the code you are running?

Thank you!

1 Like

Hi @Srikanta_K_N ! thank you for your replyiing

after i read your recommend, i used Gemini 3.0 ( gemini-3-pro-preview ) as you advised.

and this is what gemini 3 answered.

Hello! It looks like you sent an empty message.
                                                                                                    
                                                                                                    How can I help you today? I can assist with:
                                                                                                    
                                                                                                    *   **Writing and editing** (emails, essays, stories)
                                                                                                    *   **Answering questions** (facts, explanations, summaries)
                                                                                                    *   **Coding** (writing scripts, debugging, explaining concepts)
                                                                                                    *   **Brainstorming** (ideas for projects, gifts, marketing)
                                                                                                    
                                                                                                    Feel free to type your question or request below!

this is exactly same whenever i use these settings (below)

SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.NONE),
SafetySetting(HarmCategory.HATE_SPEECH, BlockThreshold.NONE),
SafetySetting(HarmCategory.SEXUALLY_EXPLICIT, BlockThreshold.NONE),
SafetySetting(HarmCategory.DANGEROUS_CONTENT, BlockThreshold.NONE)

and here is my code snippet!

class GeminiModule(context: Context) {

    private val apiKey: String = try {
        context.resources.openRawResource(R.raw.api_key).bufferedReader().use { it.readText() }
    } catch (e: Exception) {
        e.printStackTrace()
        "API_KEY_READ_FAILED"
    }

    private val factualConfig = generationConfig {
        temperature = 0.0f //floatํƒ€์ž…์˜ 0.0. temperature์€ ๋ฌด์ž‘์œ„์„ฑ.
        topK = 1 //๋‹ค์Œ ํ† ํฐ์œผ๋กœ ๊ณ ๋ คํ•  ์ตœ๋Œ€ ํ† ํฐ (ํ›„๋ณด)์ˆ˜
    }

    private val generativeModel = GenerativeModel(
        modelName = "gemini-3-pro-preview",
        // 5. 'ํŒŒ์ผ์—์„œ ์ฝ์–ด์˜จ' apiKey๋ฅผ ์‚ฌ์šฉ
        apiKey = this.apiKey,
        generationConfig = factualConfig,
       // safetySettings = safetySettings //test์šฉ ๊ธฐ๋Šฅ - blocking์„ ๋”.
    )

    private suspend fun callApi(inputContent: Content): String? {
        return withContext(Dispatchers.IO) {
            try {
                val response = generativeModel.generateContent(inputContent)
                log("์ œ๋ฏธ๋‚˜์ด ์‘๋‹ต: $response.text")
                response.text

            } catch (e: Exception) {
                e.printStackTrace()
                "API ํ˜ธ์ถœ ์‹คํŒจ: ${e.message}"
            }
        }
    }
    //์ด ์•„๋ž˜๊ฐ€ ๋ฐ–์—์„œ ์กฐ์ž‘ํ•˜๋Š” ๋ชจ๋“ˆ I/F : public ํ•จ์ˆ˜๋“ค.
   
    suspend fun analyzeTextOnly(prompt: String): String? {
        val inputContent = content {
            text(prompt)
        }
        return callApi(inputContent)
    }
}

i pass a String to this class instance

+ it always happend at first request. every nth request (not fist req.), gemini response what i exactly instruct. e.g. like below

n๋ฒˆ ์งธ ์ œ๋ฏธ๋‚˜์ด ์‘๋‹ต(๋งˆ์ดํฌ ๋…น์Œ ํ˜ธ์ถœ ์ดํ›„): # ํ˜•์‹1
                                                                                                    
                                                                                                    ์‚ฌ์šฉ์ž์˜ ๋ชฉํ‘œ: "Fatih" ๊ฒ€์ƒ‰
                                                                                                    ui ์š”์†Œ id: com.google.android.apps.nexuslauncher:id/search_container_hotseat
                                                                                                    ui ์š”์†Œ ์ขŒํ‘œ: 78, 2125, 1002, 2290
                                                                                                    ํ–‰๋™: click
                                                                                                    ์ง€์‹œ์‚ฌํ•ญ: ํ•˜๋‹จ ๊ฒ€์ƒ‰์ฐฝ์„ ๋ˆŒ๋Ÿฌ Fatih๋ฅผ ๊ฒ€์ƒ‰ํ•˜์„ธ์š”.

thank you!

thank you for your advice, now i solved it!

As a result, it was โ€œa empty prompt problem.โ€ because of my codeโ€ฆ.

when i set my api parameter to monitor how many tokens it used, i found a requestโ€™s input token is 1.

so i check my code.

in my code, Coroutnie is on going with I.O thread(this Coroutine makes a prompt ), so Main thread calls Gemini API first, not waiting a prompt that Coroutine makes.

thank you thank you!

1 Like