fix(gemini): stringify integer enum values in tool schemas#14104
fix(gemini): stringify integer enum values in tool schemas#14104BSubot wants to merge 1 commit intoNousResearch:mainfrom
Conversation
Gemini's Schema.enum field strictly requires TYPE_STRING values. When a Hermes tool declares an integer enum (e.g. discord_server's auto_archive_duration=[60, 1440, 4320, 10080]), Gemini rejects the entire request with HTTP 400: INVALID_ARGUMENT: Invalid value at 'tools[0].function_declarations[N].parameters.properties[M].value.enum[0]' (TYPE_STRING), 60 This happens even when the schema's type is 'integer' — Gemini doesn't coerce. The result is that any subagent routed to a Gemini model with the discord toolset (or any other tool with integer enums) fails every API call, spamming gateway logs with non-retryable 400s. Fix: in agent/gemini_schema.sanitize_gemini_schema, coerce every enum value to its str() representation before passing through. This is lossless for downstream consumers — Gemini echoes back the string form, and the tool dispatcher parses arguments from the model's JSON output where integer coercion already happens. Tests: - 6 new unit tests in tests/agent/test_gemini_schema.py covering integer, string, mixed, nested, items, and non-list enum cases - All 95 existing gemini adapter tests still pass
|
Likely duplicate of #13486 — same root cause: integer enum in tool schema breaks Gemini. This PR fixes it in sanitize_gemini_schema rather than in the tool definition. |
|
Duplicate of #13486. |
|
This seems like a better solution than the others, since it can cover other cases if they arise or are discovered, rather than requiring changes to the tools themselves |
|
Thanks for the thorough write-up and reproduction steps, @BSubot — this is a real bug and the fix direction is correct. This is an automated hermes-sweeper review. The same root cause was addressed on
The landed fix uses a drop strategy rather than stringify — the Closing as implemented on main. The referenced issue #13486 can be closed separately. |
Summary
Gemini's
Schema.enumfield strictly requiresTYPE_STRINGvalues. When a Hermes tool declares an integer enum (e.g.discord_server'sauto_archive_duration=[60, 1440, 4320, 10080]), Gemini rejects the entire request with HTTP 400:This happens even when the schema's
typeisinteger— Gemini doesn't coerce. Any subagent routed to a Gemini model with the discord toolset (or any other tool containing integer enums) fails every API call, spamming gateway logs with non-retryable 400s.Fix
In
agent/gemini_schema.sanitize_gemini_schema, coerce everyenumvalue to itsstr()representation before passing through. Lossless for downstream consumers — Gemini echoes back the string form and the tool dispatcher's JSON argument parsing already coerces integers.Reproduction (before this PR)
After:
Tests
tests/agent/test_gemini_schema.pywith 6 cases: integer-enum stringification, string-enum preservation, mixed-type enum, nested enum insideproperties, enum insideitems, and non-list enum dropped.test_gemini_native_adapter.py,test_gemini_cloudcode.py) still pass.Notes
enumpath insanitize_gemini_schemais touched; behaviour for every other schema key is unchanged.discord_server(tools/discord_tool.py), but the fix is tool-agnostic.