Strange Agent behavior - Agent changing llm output

Without anything changing in the prompt or the setup, my agent has started mangling the llm output.

The LLM (2.5 Flash) returns this info to the agent after using the serper.dev tool to search.

{
  "response": {
    "generations": [
      [
        {
          "text": "```json\n{\n\"brandName\": \"Bioptimizers\",\n\"productName\": \"MAGNESIUM BREAKTHROUGH NOW STEVIA FREE OPTIMIZED NUTRITION SOLUTIONS RASPBERRY-LEMONADE\",\n\"productUrl\": \"https://bioptimizers.com/magnesium-breakthrough\"\n}\n```",
          "generationInfo": {
            "index": 0,
            "citationMetadata": {
              "citationSources": [
                {
                  "startIndex": 1311,
                  "endIndex": 1444,
                  "uri": "https://www.optimoz.com.au/products/bioptimizers-magnesium-breakthrough-drink",
                  "license": ""
                }
              ]
            },
            "finishReason": "STOP"
          }
        }
      ]
    ]
  },
  "tokenUsageEstimate": {
    "completionTokens": 66,
    "promptTokens": 4758,
    "totalTokens": 4824
  }
}

But the agent output to the next node looks like this.

{
  "output": [
    {
      "thought": true,
      "thoughtSignature": "AVSoXO6bgzvCI552zdgWjBHOdtS4kutcgeaqReX5dbrHKuZEkX2Pl7xa0T7J6mnfO0xh5JCM0RMudMXl1l3IDeLOWAIrJyvTLczdpN+rueJSSZB4E5KaotsBzmXdxe/tHg=="
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO4wbSmcvIksVxv9//XGtdGouCbmjQZ7h8MT4gVeFZbKXakxVpTE4QR7lKSdHUVF0xZZBz+4zcSq4302tcj33xN6bX5B9+HFxW4OUbO6iu6831GSqC6R/itshGZ2XMeG/cXscSAXkEB7nHgu+aPAmEFtVaM+g5H6KF6r4YdILt5os/hqtOFfD8A6wYQhjPLvUr6dIcUPt4Fk7I28DPQrEWjsd3GpGXxo50RTWSW2QNp78SZyMSdcINY8HJEX1T/e6Yjs3MynPgLWzF2BnGc3lINZcCB3j+xoTwKPBCxDyDGcixpKhg8qPBlxZhCpUIHG4E9KsIz4aNEHRicQ0eINK0vMr5K49V0OgFKwZHWdCRhLXB76hMG9Wxiqyv3h"
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO4I0BzEG6MvTGezMRTHee5uPYm9WHt8tl8Vg10CeJB0b1lUGCYmeq7j/UsIWuOP/3OmDu2bugXz6Mp1RP489DMh/O9eIBFpsfK7xJfpkSPHOd0aItgbyvTtr19LzDsAYEPfhs4ROTEuPs64a1iLTfSa+6iavThO6pIZohs4VTomzER09Gau6vDRG69BluCGQ/4KNLtmLE/Ant63xv4wMdkK1CdXkcBAX3Vpqd+wPLEXTkKVvxGvwJSCqeLGgdFX+IJNql+3KlanQjMzSsOggdrFM0u7exdX2GhcOy4adU0wtUKO"
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO4pB2y6P8s0+25llwClOO+2lyEncrQXEGMn1npveR8HbsSFLyIneeCnu02SOCtyrtj5/A5WboxrXLhFxRvTs5lI6nTQbqvkqt5KR69eyI83qNivKdrUDZ/LmgZ/CvbDijkWBcxuh9c6Rv+yiT8ApsNmQ1BRfJCMK3PIqqkPn8xvBn5f1iH1CluJSradT+ocX4fSKjeMPbJsXSHtMONngo5YJHBGlPQHTSmXlq3NRswtFeG+Ngejmm8LiVfXMZ1s3X3R6VNUNGTtCQEQPZmoHmsx/4maiEDQTfCNyw5dhMZULY60dWd61LZ/B4xlYp6iYg=="
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO7vwRMwr6KnZGJ8k8MnJojm8WgZazcsrBn1lOiKgL7NTe5uItguORfJp8xXRaR35Nyi2CrLm2OtQ3lDRyk+/FL20oQCUuqVBiQyr5V5l+/8X0yo6TnpB+8OrOdO5VLFNACQupPDcxda/Lc4+KooofCQwYn3JzBbfy2pZOwbdaSD6qua5uHBXnqT2ufV+sRtUP80e7bN0o+0z8Iv/ksO8TwbGr8uGDrncA6CW6pjKdnnysTU6l8FIe8wXlwLNejiADsQv7pO0xx+JOiZix0kGhMpjKT7lbUoFA=="
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO51/RvamtpoH1zmG+cr4AaPbew/8J/Sq6Esccx5plH3h2ZJGBYcHMjiuFkL+eLrYfMP/TQ5EccWvGTMsd+RsDgcMuqHVQe4O+PrLHQ1C+t0UjkXuzu3jszddWY+bZOKekxrGeEYR3QYeTTGS8mUxKhmrg9I8oWpr63TymAByb/4k1d4ExjZTBM+LcZyoZFLImZy0XBX1Zw36IsUJHyd4pI4P2YEXdaDQy8wtw2UaiVb9WZpDZMzJCBy5LMuHia9AY4E2aCQRS2lpR30QKFCuiI0YOnGrbzcSlNe0f5opPij7UKGHyTwgG5FyqjDx5o7PDpb5w=="
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO78atEM4d0tsAKyUL2Resvad82uWrzF48OxrS3+F0j0QRQT/rIgjc+UWouEWHkhEjwTz8pUXciZMXZwYojC2pEaHDTQQcQ+RNv47yyGKhl+xMY2VRiiuDD386/USIzQlmKy0W+Jc6+X1pTN+BsojUxyyqZYsC/ZydqdfI8OAm/CfeYPs9wUnBASdGv83lIkDS57V87ocVS/AsTmFqyKvmbMNs0puNq9ev9SwbzborIqS8aI5Qc0tx4IM0K5zsXL9HACYkvPNmlM"
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO5HSnsVJ9Z7gGIUeSh8+b5U5kNPfJv6/+hivchSd5+buyBox5UbyfjiKnJzBKp0ottwj+3fP4DQKLXkk984SHNHvj6hTYae21I84+iBUdl/W/OcNG7H97XEjaEcXYyhLk7t5MVoIMCAs3qVGL1rAoxob5FnFdrvW7uW7EMzA/OtlofeDuEyMB3PzD8UqM3G634YBwDGS2nU1Ud3e381qy935Oa8Vde658lFvz7y7HfNuJ3g1vUG4d4uLfaUJ4GyHy4a0Xh+BF09jWrovvXmN3sFAMLK2aWwaEE88RkjuuRtq9LDjHV4oWkCcBTJWPJbO1/hWzyTl7gPSXZGsGXutm4="
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO4l2PN1AjO60lmZ8oIrigrBV5PQp5KavLHCajHaPAzYlUdSanTF8RfpcfQNayjSUKyhbVCjwoT0pvcXGJDeZ5Y61BLj1j5eEyr4gSbZM7aWB6Ms5jJ61n2PPKKFLpjhpNzZ8ftPyglcmuKRI8+d9/WEuWkcdYesOcPM+KmiPqUsRzrh/9sXicFNkD4so+kGyDjK+3freP+5rj33UDTnTBUvA9M99/KR7yjdF4kYf/aMHs+vVjAqbZUX66F+fAi+xctJmmzUU6kgnAtyF0gtu+/LtjSrUBwOpFNO"
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO518AGKlJwxQnR9VQWfZXHH3XvI2+q9Uh34Q83LMWSuoYwBzHFMESUzmX9zw8e+W9/MQiBnS4lIYUdd0oxrrEIZQxeZMYdL6p4aYefD7XWvez4lvmaZYWBEEbT0TeJVRnMF7MFpajzKuxYlDi27GQkPv0pfjBvrasnjnC3nZP4ZoDYtmCh03jzwGG9lFc/N4C+Yl0VSYLWFYF49qbM+L9RSqEse+dzFZLyHiDetSW46cltRuriDJff+jfg4QXksFmubSOggzwavft7ra59LlBH5MHLa9V1oWbr4jvCpINcSNGMaRAXrx1AGWmlymg=="
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO7qVaX52zZe9iC8o28EEDkmdL5B5gNI86NXqomy/I73YUH9RKkVMNfICt9DdtnD1DeacUEWrxH13yGDCwL+OPgiB0NLJ7noWTJsrEo2IrJKH+X+MirOgRtw3sTpiYl/fE4+HrX2WAY+9k5FlX8N4JLe6neuMB0oWJqBfv6r45PuV+wwU+t4brombrRmnfTN/mitUKSdSa0v+HjK0xx35jbwktbNBZi19VvLRLhF0BIcAz08nTxBi1r9x1S5Y+CP7f2xtYMnQQ9l"
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO4d7E40QIw3f19utwsRiJ3LjoMNM8nZ/ppW7QndTTbg1jDcVIQybFA61yBj66+YEzxkIoZir53C7Vt1iaSnHW983vxyc9UaktpHNq2/cfVjnwGANI4xMb2uPWJ71VLqMl86YDUFGjZ779Q0LVNk8e8tK2wyi40K0GPwBS4rPFT3jM/0US+6db2CAoAKL+eg0+LKEULSmPhU+DTGA7SyP+Bj+3MPeXKrhks3xp7Cc1D2w0s46A2338Acao/8cG86N1b+KrC08OEjY5VSBAPgV1fenJWJyebq0Z01"
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO4WoQ8mkP2XziOk7vn3FgLPF/Z2XuaTEGOuW/EnojwvQMwsxUIJbxzkQ/u5+B5+TpDnlnLr3bKfveYgm3z5UiSI1np3/jfZQEmvdAq5oPg3QX3BLihL5y68gF6feC/G5qyPqjLVO64RAVhl3+77mLtogv4Mx3WILqdxO+dNCp28iZfohJHypBceNBa4fNxaxbcrXvGQ7PASVJvBuVF3WrWZI5olwXlzHyvWjh9muIyl5UPaCn6LEooJFfnYbjfZSRgWE9KkK+V5PQ=="
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO5EWUZxZWITuASnRMoKJwkKb9veI1oGt0rznUOXAu9izh+/BFvmHWvMJUAf0/piVGwjJkp1db60zu4MBrMQPTjLw6Hb6czpRxWyB+pJMnnJ0y/yhceVFZOhSflY9fuz9yD2iP5sZ4Gd1rRU/7YCLXrlGr419UbA848MV1kdGV/tyo8UlhfaWy6WQ8uT/A5BBRTJ9zGcgTbInPjMn4QqYRrJaHc4XsedzxcjJBCoKSQ1EeBMhoLd4goCmLGnt0Da11plsVCNaO0UT9fJ59MlhLoJwp9IF6Qqlw4K4uXyESRl6TtKhYXe9H42OEZ84UrQMDTv0MMYlDDYG/SopBKTlHRJLfdH"
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO7AUY38GQ0jBGM93r4GHXojQ3YcM7OJdqCN2JBidPC53UssF0ujlkg8acsQyoNZWfjW54r7/93/OFDZ12/Livlp1K5rX9dMULqKa2zH5JS4sZOHEHM1RgUiLGLauPKmEQRbF0L0x8bHvZfMXhNRLtxVZf1jnsoafYTSBbtaKeK/nqZYa3XpBYbyQc7pE4XTfDeQ8zgesnq4YqB5buuXXpBtdtJedFMm75FaXX96iZzPKE/enDIIy6fj+qSN1/yChuq5DAdur69F7RLbJjX5sDcfR3wh1VSpw70ctD/Z1Fq04Vq3tZGZ3yHxJ2AV1WfeQRltXi2gqJxZ9b6xKHhQhrlGMPqDg4apXIMOFhV/RCtheQ=="
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO6aG4CQ0F98jEw4AsJNpYOPJJrzC7df0zFzTdh3Eik/5U68AnCjNs5gFbfE21NtSSqOcEYHZ4RunuFb7n4njiSORuvWRlpw1diaRKQg+pLN2UqN0bcwgKixBsrWU8+hK2BmA32ABFOYzHZkGaSxEBT1sxW0gG5KFjJ2AjMudWosvhmpOCNhz3O+pgIOTwOkrSVwdmrAlOFIIKJ1BfZGyDesh+3lHGtZ++/RVT35+Lhkv82YKOwyRKxdf5rb1j2jQdLiC5Dk2VroL1jxBhcJtCQnM/4="
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO4NJwzl8PswO593QujIlRPgswnhsLs7HqocO28OuR8SRKp/Y+9MQyaJdhBoQN/hovuCp42JX36rauCuqxLGRuRIHdBxTWhln1ulU4EjtBZQC1pGJCqOXDlipFO8l0mhc8B8BYMx6Jx5QDKgMNjiir5KKm/dT4ESKP5czsTe+2vIMsxQQD8Lnr87KsWwU8oz6IGDvznUeW9qoMesLsc85kGei5GhrmSVLhplqH5Skg2xH69jwwDtkOPtqV98Iu0rRvLb+pjlRZDNT2g9kVeOPfdefUHCw6bRrNEGwGe+mRRQ7PiG"
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO6wTPUdmL0ONCUrQdkzzIbGSX3UcoQCRRGevw4RZEus1OCel2TDv4WhmhHPQYPsIlZh+ATCPe5VlB7liOLhw9Vso7Y+c1jpWNkmYevrslXuQ671CL3fySHZFI6ye2V9OY8IllVEza6MxJyk9GW56JQgpnxatXIA/W0u9VJdkr+s4ZK6GWcv1BULkP0NDHIYzPIfXGpD9tlidtAsTKJ6SG7mk5GlbfWNQrhDOWbJP123oFokkScoUNI/0Qs33tNpafxHPfVQ9LAl4y+YCNoWdmZ+9cwizAgWSACzHYfn"
    },
    {
      "thought": true,
      "thoughtSignature": "AVSoXO4UkcRchKaNKkb/l6/DdUV+2+U28aeBRCsTAKBm3/SMCsrwMaQS34wcvtCE9o0N8q8rmgHlTl22oPr3i4YbX6Eh/4BBhegyEiqGVj8I/yIhUqX5jgR/1KxTWs40y46Bw6Ua4swKrFCXrGzU+jE="
    },
    {
      "type": "text",
      "text": "```json\n{\n\"brandName\": \"Bioptimizers\",\n\"productName\": \"MAGNESIUM BREAKTHROUGH NOW STEVIA FREE OPTIMIZED N"
    },
    {
      "type": "text",
      "text": "UTRITION SOLUTIONS RASPBERRY-LEMONADE\",\n\"productUrl\": \"https://bioptimizers.com/magnesium-breakthrough\"\n}\n```"
    }
  ]
}

The correct information is out at the bottom but broken up in a weird way. Before today, it returned exactly what the llm spit out and was great. Now, even if I go back to old successful executions they no longer work.

Thanks for any help!

Information on your n8n setup

  • n8n version: 1.95.2
  • Database (default: SQLite): sqlite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): cloud
  • Operating system: macOS
2 Likes

Having the same issue, I didn’t change anything on my workflow and now the AI agent is throwing “thought” and “thoughtSignature” besides the actual content on its output. This is happening with Gemini 2.5 Flash not thinking models.

Same here!

@ldaniel-jmz, @A_Salim… I made this Code Node to extract the data until this gets fixed.

const output = $input.first()?.json?.output || [];

// Concatenate all text values where type is "text" in order
const llmMarkdown = output
  .filter((item) => item.type === "text" && item.text)
  .map((item) => item.text)
  .join("");

// Find the content inside the markdown code block
const match = llmMarkdown.match(/```(?:[a-zA-Z]+)?\n([\s\S]*?)\n```/);
const llmText = match ? match[1].trim() : llmMarkdown.trim();

try {
  // Try parsing as JSON
  return [{ json: { output: JSON.parse(llmText) } }];
} catch {
  // If it's not JSON, return as is
  return [{ json: { output: llmText } }];
}

Ha ha, I’ve got this problem just today and saw you fixed it 3 min ago. Lucky day

Same issue here - with Gemini 2.5 Flash (05-20) and Gemini 2.0 in the Google Gemini Chat Model node. I tried different n8n versions with the same result, so switched in an OpenRouter chat model node first with ChatGPT o4 mini and then with Gemini 2.5 Flash 05-20 Thinking. It worked with BOTH of those models in OpenRouter.

So…long story short, either the Google Gemini Chat Model Node has an issue, or all the Gemini models are somehow behaving badly (although the fact Gemini worked through the OpenRouter node says it’s the node that is the problem).

This works for the first message, but if you’re using chat memory it’ll start to break. Look after the second message:

Hi everyone,

I’m experiencing the same strange agent behavior described in this thread.

My setup is:

  • n8n Version: 1.95.2
  • LLM Model: Gemini 2.5 Pro
  • Hosting: Self-hosted

Hoping a solution is found soon!

Edit: Everything is working as expected now!

This seems to have been fixed.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.