Gemini 2.5 Pro inserting random text and format tokens around json responses

,

Using the API, sending a query with an application/json mime type is inserting “```json” and “```” at the beginning and end. Bizarrely, it also often starts with the text shame or shamefully before outputting the json. Just manually sanitizing for now, but given that the API worked fine for every prompt before today I suspect there’s some kind of weird bug here

edit: I also just got shamefully-self-plagiarized at the start of the json lol the word plagiarize appeared nowhere in the data

12 Likes

This is super weird, things worked great yesterday, but now it just somehow starts with

Raw response text: shame

[
  {

Experiencing the same issue with ‘‘gemini-2.0-pro-exp-02-05’’ model
What does those “shamefully” and “shame” texts before the JSON mean?

I also ran into this weird issue when trying to upload a pdf and return structured output.

I suppose shame, shamefully, and shamefully-self-plagiarized are tokenised next to each other in the vectorspace. This is a weird issue and I suppose it’s a bug at Google.

same issue. happening all the t9ime with gemini-2.0-pro-exp-02-05 + structured output. super annoying and also very creepy

1 Like

OK, this is suddenly a persistent issue when using structured outputs, even in aistudio !

I reported this as well 10 days ago or so. No resolution yet.
It affects also 2.0 Flash. It started in the last 2-3 weeks and there is no prompt that can overrule it.
It makes the model unusable even if it’s otherwise great.
Same prompt is working fine in AI studio, so it’s something happening only with the APIs.
Please fix it - thanks!

@Sangeetha_Jana, this requires more attention. After setting a response mime type and providing a response schema, I’m getting responses as (see excerpt):

"candidates": [
        {
            "content": {
                "parts": [
                    {
                        "text": "ny\n```json\n{actual_json_here}\n```"
                    }
                ],
                "role": "model"
            },
            "finishReason": "STOP",
            "index": 0
        }
    ]
1 Like

It is also happening for me when querying structured outputs via the official NodeJS SDK.
I am using the model: gemini-2.0-pro-exp-02-05.

There are random occurencies, when the “shame” string is prepended to the response text, followed by a valid JSON response. I could not find any correlation between input/output, when these “shame” strings occur.

As for now, I just forced to process all the Gemini responses with the function: Extract JSON from string JavaScript · GitHub

Looking forward to the resolution of this nasty issue.

2 Likes

Likewise for us, it has started adding that text in the response today.

ny\njson\n{ ```

We are utilizing Gemini 2.5 through the OpenAI-compatible API.

Can confirm I’m seeing a surprise “ny\n” too, on gemini-2.5-pro-preview-03-05 as well as on exp, through the Gemini API.

We’re also seeing the “ny\n” issue and a ton more other invalid JSON responses. We’re even seeing other random tokens interleaved with the json response that are not related to our request at all. This just started happening to us a day or two ago. Before that, gemini 2.0 pro exp and gemini 2.5 pro felt really stable. Seems to be there is a very serious bug Gemini introduced that I hope they’re all hands on deck trying to fix right now.

2 Likes

Seeing consistently “ny```json…” in the beginning and weird responses today. Was working perfectly fine till yesterday

I get consistently “ny```json…” in the beginning of the json outputs as well, the code worked fine yesterday

My usage has always had that, I think even 2.0 flash does it. I gave up and made a function to strip it out if present. (Not sure on my MIME type)
Insight into how to resolve would be appreciated.

Same issue. Getting ‘ny\n’ in front of the json file. I am working with openai compatible mode and it just cause my code to crash and leave me no choice but to switch back to 2.0 flash.

I’ve found the same over the past couple of days, both with 2.5 Pro Experimental and Preview. I was able to replicate in AI Studio, too.

Same issues here, have been seeing “ny” and sometimes “shame” before json output with 2.5 pro

Screenshot 2025-04-07 151716
lol

1 Like

lol. what’s this mean? Does this mean it use data from gpt-4-turbo to train the model or something else?

1 Like