Getting error while using webhook and simple memory

Bad request - please check your parameters

[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:streamGenerateContent?alt=sse: [400 Bad Request] * GenerateContentRequest.contents[0].parts: contents.parts must not be empty.

whenver im using simple memory im getting error.

which gemini model are you using ? can you share the json file if possible

Hi ,

The json is the data used in simple memory

[
{
“action”: “loadMemoryVariables”,
“chatHistory”: [
{
“lc”: 1,
“type”: “constructor”,
“id”: [
“langchain_core”,
“messages”,
“HumanMessage”
],
“kwargs”: {
“available_data”: [
“-Some pre defined data)”
],
“user_input”: “hi”,
“additional_kwargs”: {},
“response_metadata”: {}
}
},
{
“lc”: 1,
“type”: “constructor”,
“id”: [
“langchain_core”,
“messages”,
“AIMessage”
],
“kwargs”: {
“content”: “Hi Sathish! How can I assist you today? :blush:”,
“tool_calls”: ,
“invalid_tool_calls”: ,
“additional_kwargs”: {},
“response_metadata”: {}
}
}
]
}
]

whenever i use simple memory that time only im facing issue .

Gemini json:

{
“messages”: [
“System: You are Sathish’s personal AI assistant ‘JARVIS’.\n\n\nYou can see and use Available_Data, which contains user-specific information.\nWhen the user sends a User_Input, reply based on general knowledge or by using Available_Data if it’s relevant.\nIf Available_Data is missing but the question can still be answered from general knowledge, go ahead and answer it.\nOnly say you don’t have enough information if both general knowledge and Available_Data can’t help.\n\n​:brain: Example Behaviors:\nUser Input: "Tell me a joke" → :white_check_mark: AI responds with a joke.\n\nUser Input: "What are calories?" → :white_check_mark: AI explains what calories are.\n\nUser Input: "What’s my BMI?"\n\nIf Available_Data includes height and weight → :white_check_mark: AI calculates BMI.\n\nIf not → :x: AI should not say "I don’t have any information" generally — it should say "To calculate your BMI, I need your height and weight."\n\n\nHuman: undefined\nAI: Hi Sathish! How can I assist you today? :blush:\nHuman: {"User_Input":"hi"}”
],
“estimatedTokens”: 213,
“options”: {
“google_api_key”: {
“lc”: 1,
“type”: “secret”,
“id”: [
“GOOGLE_API_KEY”
]
},
“base_url”: “https://generativelanguage.googleapis.com”,
“model_name”: “gemini-1.5-flash”
}
}

Error

{
“errorMessage”: “Bad request - please check your parameters”,
“errorDescription”: “[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:streamGenerateContent?alt=sse: [400 Bad Request] * GenerateContentRequest.contents[0].parts: contents.parts must not be empty.\n”,
“errorDetails”: {},
“n8nDetails”: {
“time”: “4/20/2025, 5:21:08 PM”,
“n8nVersion”: “1.88.0 (Self Hosted)”,
“binaryDataMode”: “default”,
“cause”: {
“status”: 400,
“statusText”: “Bad Request”,
“attemptNumber”: 1,
“retriesLeft”: 6
}
}
}

Hi, @Sathish

Are you sure you’re passing something to the AI agent? I mean, how are you handling the data coming from the Webhook?

Yeah I am also struggling with this but trying to use the Redis Chat Memory. It seems that content is not being sanitized for JSON going into or coming out of the memory modules.

I’m guessing that this could be specific to Google API (common factor with me) and that it is outputting unsafe, unescaped results. When a bad one gets stored in the cache, it screws up every subsequent transaction as it’s included in the context.

OP, in one of your samples, the JSON is broken on the strange characters in tool_calls and invalid_tool_calls.

(NOTE: when you post code like this please be sure to format with tools here as preformatted text similar to the foolowing – I had to fix your fancy quotes for straight quotes before checking the format in an online JSON format validator.)

The problem in your second example is the following line which should have quotes escaped like this:

            "System: You are Sathish’s personal AI assistant ‘JARVIS’.\n\n\nYou can see and use Available_Data, which contains user-specific information.\nWhen the user sends a User_Input, reply based on general knowledge or by using Available_Data if it’s relevant.\nIf Available_Data is missing but the question can still be answered from general knowledge, go ahead and answer it.\nOnly say you don’t have enough information if both general knowledge and Available_Data can’t help.\n\n​:brain: Example Behaviors:\nUser Input: \"Tell me a joke\" → :white_check_mark: AI responds with a joke.\n\nUser Input: \"What are calories?\" → :white_check_mark: AI explains what calories are.\n\nUser Input: \"What’s my BMI?\"\n\nIf Available_Data includes height and weight → :white_check_mark: AI calculates BMI.\n\nIf not → :x: AI should not say \"I don’t have any information\" generally — it should say \"To calculate your BMI, I need your height and weight.\"\n\n\nHuman: undefined\nAI: Hi Sathish! How can I assist you today? :blush:\nHuman: {\"User_Input\":\"hi\"}"

I’m kind of stuck trying to find a solution for this. I think it is best to sanitize the content before it goes into the cache but that’s not happening. Should it be happening or can we make it happen? MAYBE the answer is in explicit instructions to generate only safe, escaped answers?