-
Notifications
You must be signed in to change notification settings - Fork 796
Description
This is a product issue — the API server rejects valid JSON Schemas with an opaque error. The SDK passes the schema through correctly; the rejection comes from the Gemini API itself. Filing here since the SDK is the interface and there's no public product issue tracker.
Environment details
- Programming language: Python 3.11+
- OS: Any (reproduced on Colab, macOS, Linux)
- Language runtime version: Python 3.11
- Package version:
google-genailatest (tested with 1.x) - Model:
gemini-3-flash-preview
Steps to reproduce
- Open the self-contained Colab notebook: Open in Colab · Source on GitHub
- Set your
GEMINI_API_KEYin Colab Secrets - Run all cells
The notebook generates a single tool with N array properties, each with a configurable maxItems value. It sweeps across different field counts and values to isolate the cumulative budget.
What happens
When using function calling with parametersJsonSchema, the API returns INVALID_ARGUMENT with no diagnostic information when the cumulative sum of maxItems values across all properties in a tool schema exceeds ~960. This affects both ANY and AUTO modes.
Other JSON Schema numeric constraints (maximum, minimum, maxLength) at identical values are completely unaffected.
Results
Single field — boundary sweep:
1 field × maxItems=N (sum = N)
maxItems │ ANY AUTO
──────────────────────────────────
971 │ PASS ✓ PASS ✓
972 │ FAIL ✗ FAIL ✗
8 fields — cumulative sum matters:
8 fields × maxItems=N (sum = 8×N)
maxItems sum │ ANY AUTO
────────────────────────────────────────
119 952 │ PASS ✓ PASS ✓
120 960 │ FAIL ✗ FAIL ✗
Different distributions, same sum — all behave consistently:
Fields × maxItems = Sum │ ANY AUTO
──────────────────────────────────────────────
Under budget (~950):
1 × 950 = 950 │ PASS ✓ PASS ✓
10 × 95 = 950 │ PASS ✓ PASS ✓
50 × 19 = 950 │ PASS ✓ PASS ✓
Over budget (~980):
1 × 980 = 980 │ FAIL ✗ FAIL ✗
10 × 98 = 980 │ FAIL ✗ FAIL ✗
50 × 20 = 1000 │ FAIL ✗ FAIL ✗
Control — stripping maxItems fixes it:
Same failing schemas with maxItems removed → all PASS ✓
Cross-keyword comparison (20 fields × value=200, sum=4000):
Keyword │ ANY AUTO
──────────────────────────────
maxItems │ FAIL ✗ FAIL ✗
maximum │ PASS ✓ PASS ✓
minimum │ PASS ✓ PASS ✓
maxLength │ PASS ✓ PASS ✓
Key observations
-
Both ANY and AUTO modes. Unlike the enum complexity issue, this budget applies to both calling modes.
-
Cumulative sum is the budget. The threshold is ~960 regardless of how the
maxItemsvalues are distributed across properties. 1 field withmaxItems=972fails, as do 8 fields withmaxItems=120each (sum=960). -
Only
maxItemsis affected.maximum,minimum, andmaxLengthat identical or even larger cumulative values all pass. -
Error is completely opaque. The response is
INVALID_ARGUMENTwith no indication of which property, what the limit is, or thatmaxItemsis the cause. -
Production impact. Tool schemas generated from OpenAPI specs commonly have many array fields with
maxItemsconstraints. A typical CRM search tool with 20 array fields each havingmaxItems: 100(sum=2000) will silently fail.
Expected behavior
-
The API should either accept these schemas or return a descriptive error indicating what exceeds the limit, which property is responsible, and what the limit is.
-
If a cumulative budget on
maxItemsis intentional, it should be documented so developers can design schemas accordingly.
Workaround
- Strip
maxItemsandminItemsfrom tool schemas before sending to Gemini, and validate array length constraints in the application layer instead - If
maxItemsmust be included, ensure the cumulative sum across all properties stays well under ~960