Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Gemini API [400 Bad Request] - Array fields breaks function calling

ppm
Bronze 1
Bronze 1

Using the node.js SDK: @Google/generative-ai@0.14.0

This function declaration worked well one day or two days ago, but now it's broken.

 

```

{
  name: "cancelReminders",
  description: "Cancel some reminders.",
  parameters: {
    type: FunctionDeclarationSchemaType.OBJECT,
    properties: {
      ids: {
        type: FunctionDeclarationSchemaType.ARRAY,
        description: "An array of string IDs of the reminders that the user wants to cancel.",
        nullable: false,
        properties: {}
      },
    },
    required: ["ids"],
  },
}
```
 
Error message:
[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent: [400 Bad Request] Request contains an invalid argument.
 
How can I correctly set up array fields?
Solved Solved
0 4 1,876
1 ACCEPTED SOLUTION

Although you have `ids` set to be an array, you don't specify what type of array it should contain.

You can specify the type using the `items` attribute of the definition.

See https://ai.google.dev/api/rest/v1beta/cachedContents#schema

So that part might look something like:

      ids: {
        type: FunctionDeclarationSchemaType.ARRAY,
        description: "An array of string IDs of the reminders that the user wants to cancel.",
        nullable: false,
        properties: {},
        items: {
          type: "STRING",
          description: "The ID of the reminder the user wants to cancel",
          nullable: false
        }
      },

View solution in original post

4 REPLIES 4

were you able to solve it, im getting the same error

were you able to solve it???

Although you have `ids` set to be an array, you don't specify what type of array it should contain.

You can specify the type using the `items` attribute of the definition.

See https://ai.google.dev/api/rest/v1beta/cachedContents#schema

So that part might look something like:

      ids: {
        type: FunctionDeclarationSchemaType.ARRAY,
        description: "An array of string IDs of the reminders that the user wants to cancel.",
        nullable: false,
        properties: {},
        items: {
          type: "STRING",
          description: "The ID of the reminder the user wants to cancel",
          nullable: false
        }
      },

Thanks! This solves my problem.