Couldn't switch language mid-conversation using Gemini 2.5 Flash

As the title says.

I have tried several prompts in the ‘system_instruction’ parameter. Below is one of the examples:

Language: Use Chinese Mandarin. **Follow the user's language if they speak in another during mid-conversation**

I have been trying to make the model switch languages, mainly English and Mandarin, but to no avail. It can only work when I explicitly say ‘Use English’ or ‘Use Mandarin’ through the ‘send_message’ function.

How can I make the model work as I intended?

Hi @Ho_Zhengying, could you try providing more detailed system prompt, along with a few-shot example?

For example:

Use Simplified Chinese (Mandarin) as the default language for all responses. If the user switches to another language during the conversation, detect the change and continue replying in that new language. Maintain consistency with the user's most recent language choice.


1. User starts in Chinese, switches to English:

User: 请用中文回答我今天的天气如何?

Assistant: 今天的天气是晴天,气温约为28摄氏度。

User: Actually, can you tell me what the UV index is too?

Assistant: Sure! The UV index today is 7, which is considered high. Please wear sunscreen if you're going outside.

2. User starts in English, switches to Chinese:

User: What's the population of Shanghai?

Assistant: As of the latest data, Shanghai has a population of approximately 24 million.

User: 那北京的人口是多少?

Assistant: 北京的人口大约是2180万。