Gemini rejects tool JSON schema with array of types

I have a tool in my prompt that looks like this (abbreviated):

{
    "name": "describeProblem",
    "description": "Describe the problem in simpler terms for future analysis",
    "parameters": {
        "type": "object",
        "required": [
            "correctAnswerFields"
        ],
        "properties": {
            "correctAnswerFields": {
                "type": [
                    "string",
                    "array"
                ],
                "description": "Format it as a list of fields"
            }
        }
    }
}

I get an error like this: Invalid JSON payload received. Unknown name \"type\" at 'tools[0].function_declarations[0].parameters.properties[2].value': Proto field is not repeating, cannot start list.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [ { "field": "tools[0].function_declarations[0].parameters.properties[2].value", "description": "Invalid JSON payload received. Unknown name \"type\" at 'tools[0].function_declarations[0].parameters.properties[2].value': Proto field is not repeating, cannot start list." } ] } ] } } ]

JSON Schemas allow lists of types.

The syntax for the array of string is wrong, we can’t declare an array of string by simply putting a comma between array and string.
This cookbook sample shows several instances of array declarations (some with more involved items, that are themselves objects). The code works, I have tested it. Cookbook: Extract structured data using function calling  |  Gemini API  |  Google for Developers

Without giving you the complete answer (it helps to work this through and learn), you should declare correctAnswerField and then use that in defining correctAnswerFields, the second being the Array type.

Hope this helps!

1 Like

Welcome @Ian_Bicking

If you want to convey that the "correctAnswerFields" is a list of strings, then you’d have to describe this as an array and then specify the type of items that it takes.