Gemini Flash 2.5 sometimes returns duplicate items in list outputs – why does this happen?

Hi everyone,

I’m working on a project using the gemini-2.5-flash-preview-05-20 model and encountering a consistent issue I’d like some insight on.

Context:

I’m building an evaluation system using LangGraph + LangChain. The setup is structured in Python with the following environment:

Python 3.11  
LangGraph: 0.3.20  
LangSmith, LangChain Core, Community, OpenAI modules  
LangChain Google GenAI: 2.1.4  
FastAPI + Celery (Redis)  
MongoDB (Motor)  
Gemini model: gemini-2.5-flash-preview-05-20 

I pass prompts to Gemini asking it to return outputs in a specific format (e.g., a list of feedback points or suggestions based on input text). The responses are generally correct in format and content.

Issue:

Occasionally, the returned list contains duplicate entries — identical sentences repeated multiple times. Here’s a simplified example:

[
  "Use more polite language when addressing customers.",
  "Avoid using slang in professional contexts.",
  "Use more polite language when addressing customers."  // duplicate
]

Because of this, I always have to post-process the output to deduplicate it. I’m wondering:

  • Why might this be happening?
  • Is it a known behavior of the Gemini Flash model?
  • Are there any prompt engineering techniques or system instructions that help reduce this?

If anyone else has faced something similar or has suggestions on how to better control this behavior, I’d really appreciate your insights!

Thanks in advance,

Similar issue here. In my case, gemini-2.5-flash-preview-05-20 calls completely same function call in the last of message, like this:

When gemini should call A, B, C sequently, but actual response is:
call A
call B
call C
call A ← unneeded, but sometimes added

So I added additional prompt like “Do not repeat exactly same function call in single response.” and the issue is gone (almost, not competely).