fix(gemini): drop integer/number/boolean enums from tool schemas (#15082)
Gemini's Schema validator requires every `enum` entry to be a string, even when the parent `type` is integer/number/boolean. Discord's `auto_archive_duration` parameter (`type: integer, enum: [60, 1440, 4320, 10080]`) tripped this on every request that shipped the full tool catalog to generativelanguage.googleapis.com, surfacing as `Gateway: Non-retryable client error: Gemini HTTP 400 (INVALID_ARGUMENT) Invalid value ... (TYPE_STRING), 60` and aborting the turn. Sanitize by dropping the `enum` key when the declared type is numeric or boolean and any entry is non-string. The `type` and `description` survive, so the model still knows the allowed values; the tool handler keeps its own runtime validation. Other providers (OpenAI, OpenRouter, Anthropic) are unaffected — the sanitizer only runs for native Gemini / cloudcode adapters. Reported by @selfhostedsoul on Discord with hermes debug share.
This commit is contained in:
@@ -73,6 +73,20 @@ def sanitize_gemini_schema(schema: Any) -> Dict[str, Any]:
|
||||
]
|
||||
continue
|
||||
cleaned[key] = value
|
||||
|
||||
# Gemini's Schema validator requires every ``enum`` entry to be a string,
|
||||
# even when the parent ``type`` is ``integer`` / ``number`` / ``boolean``.
|
||||
# OpenAI / OpenRouter / Anthropic accept typed enums (e.g. Discord's
|
||||
# ``auto_archive_duration: {type: integer, enum: [60, 1440, 4320, 10080]}``),
|
||||
# so we only drop the ``enum`` when it would collide with Gemini's rule.
|
||||
# Keeping ``type: integer`` plus the human-readable description gives the
|
||||
# model enough guidance; the tool handler still validates the value.
|
||||
enum_val = cleaned.get("enum")
|
||||
type_val = cleaned.get("type")
|
||||
if isinstance(enum_val, list) and type_val in {"integer", "number", "boolean"}:
|
||||
if any(not isinstance(item, str) for item in enum_val):
|
||||
cleaned.pop("enum", None)
|
||||
|
||||
return cleaned
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user