Gemini API (gemini-2.0-flash-exp
) appears to block open-ended object
parameters in function schemas, requiring workarounds like serializing JSON into a string.
Issue:
When defining a dynamic params
object (no predefined properties), Gemini returns an error:
{
"type": "function",
"function": {
"name": "execute_operation",
"description": "Execute an operation",
"parameters": {
"type": "object",
"properties": {
"operation": { "type": "string", "description": "Name of the operation" },
"target": { "type": "string", "description": "Target of the operation" },
"params": {
"type": "object",
"description": "Dynamic parameters for the operation"
// No predefined properties (intentionally left open)
}
},
"required": ["operation", "target", "params"]
}
}
}
Error message:
{
"error": {
"code": 400,
"message": "* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[params].properties: should be non-empty for OBJECT type\n",
"status": "INVALID_ARGUMENT"
}
}
Failed Fixes:
additionalProperties: true/{}
➔ Ignored, same error.- Dummy property (e.g.,
"_do_not_use": { "type": "string" }
) and having required properties empty ➔ Gemini dumps all parameters into the dummy key as a string.
Only Workaround:
Define params
as a string
and instruct the model to output JSON:
"params": {
"type": "string",
"description": "Dynamic parameters as a JSON string"
}
This works, but forces manual parsing and doesn’t feel reliable.
Is this a deliberate restriction or a bug and will Gemini support open object
parameters in the future?
Reproducible:
- Model I am using:
gemini-2.0-flash-exp
(other providers handle open objects fine).
TL;DR: Gemini’s schema validation blocks dynamic object
parameters. The only workaround is using a JSON string, which is clunky. Confirming if this is a limitation or a bug.