fix(gemini): stringify integer enum values in tool schemas#14104
Open
BSubot wants to merge 1 commit intoNousResearch:mainfrom
Open
fix(gemini): stringify integer enum values in tool schemas#14104BSubot wants to merge 1 commit intoNousResearch:mainfrom
BSubot 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
Collaborator
|
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. |
Collaborator
|
Duplicate of #13486. |
This was referenced Apr 23, 2026
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.