Repository navigation
fix(ai/gemini): coerce numeric/boolean enum values to strings - #104567
Conversation
Gemini Function Calling only accepts string enum values (see https://ai.google.dev/gemini-api/docs/function-calling). Tool schemas containing enum: [1,2,3] or enum: [true,false] were passed through unchanged, causing Gemini to reject the entire request with 400 TYPE_STRING errors at 'function_declarations[X].parameters...enum[N]'. Extend cleanSchemaForGeminiWithDefs to coerce enum and const values via a shared helper (number/boolean/bigint -> string, drop null and non-coercible entries, de-duplicate), and retype the containing schema as 'string' since Gemini's validator only accepts enum on string-typed schemas. Adds seven vitest cases covering numeric/boolean enum, const, nested schemas, and dedup/empty-after-coercion edge cases. Fixes openclaw#104566 Co-Authored-By: Claude <[email protected]>
|
Codex review: needs real behavior proof before merge. Reviewed July 11, 2026, 7:31 PM ET / 23:31 UTC. Summary PR surface: Source +38, Tests +73. Total +111 across 2 files. Reproducibility: yes. Current main deterministically leaves numeric and boolean enum entries unchanged, and the linked issue supplies the corresponding live Gemini Review metrics: none identified. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Keep the contract-aligned provider-boundary implementation and add one redacted live Gemini request using the exact current head, showing that an integer or boolean enum is accepted and the tool call completes with the expected runtime argument type. Do we have a high-confidence way to reproduce the issue? Yes. Current main deterministically leaves numeric and boolean enum entries unchanged, and the linked issue supplies the corresponding live Gemini Is this the best way to solve the issue? Yes. The final implementation is the narrowest maintainable fix: it changes only the existing Gemini-facing schema projection and matches Google’s documented primitive-enum encoding while preserving the declared type. citeturn1view0turn1view1. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f0676a7a7951. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +38, Tests +73. Total +111 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
Address @clawsweeper review on openclaw#104567: The initial patch set cleaned.type = 'string' inline while visiting the 'enum' or 'const' key. For schemas where 'type' appears AFTER 'enum' / 'const' in the input object — a valid ordering since JSON Schema property order is not semantic — a later 'type' pass would overwrite the coercion via the tail 'cleaned[key] = value' branch, and Gemini would still receive an invalid declaration. Move the type override out of the loop: track whether any enum/const was coerced via a boolean flag, and force cleaned.type = 'string' after the loop finishes. This makes the fix independent of input property order. Also add curly braces around single-line ifs to satisfy check-lint (eslint(curly)) which failed on the previous commit. New reversed-order regression tests added. Co-Authored-By: Claude <[email protected]>
|
Thanks for the review, 1. Property-order regression — fixedThe reviewer bot was right (0.99 confidence, and the failing case reproduces trivially). The initial patch set Fix: track coercion with a Reversed-order regression tests added in
2. Real behavior proof — before/afterI mirrored the same change into the shipped Before (current main / released 6.11 / beta.5 without this patch)
→ Gemini rejects with:
After (this patch, both orderings, all coercible types)Gemini 2.5-flash / 2.5-flash-lite sub-agent invocations that were 100% failing on the same install (webchat dashboard → sub-agent spawn with full tool set) now complete normally end-to-end. Tool arguments come back as strings and are converted back to number/integer/boolean by the existing tool-argument coercion layer at execution time (which the review correctly noted was already in place — the runtime scalar contract is preserved). 3.
|
|
Merged via squash.
|
…aw#104567) * fix(ai/gemini): coerce numeric/boolean enum values to strings Gemini Function Calling only accepts string enum values (see https://ai.google.dev/gemini-api/docs/function-calling). Tool schemas containing enum: [1,2,3] or enum: [true,false] were passed through unchanged, causing Gemini to reject the entire request with 400 TYPE_STRING errors at 'function_declarations[X].parameters...enum[N]'. Extend cleanSchemaForGeminiWithDefs to coerce enum and const values via a shared helper (number/boolean/bigint -> string, drop null and non-coercible entries, de-duplicate), and retype the containing schema as 'string' since Gemini's validator only accepts enum on string-typed schemas. Adds seven vitest cases covering numeric/boolean enum, const, nested schemas, and dedup/empty-after-coercion edge cases. Fixes openclaw#104566 Co-Authored-By: Claude <[email protected]> * fix(ai/gemini): make enum retyping property-order independent Address @clawsweeper review on openclaw#104567: The initial patch set cleaned.type = 'string' inline while visiting the 'enum' or 'const' key. For schemas where 'type' appears AFTER 'enum' / 'const' in the input object — a valid ordering since JSON Schema property order is not semantic — a later 'type' pass would overwrite the coercion via the tail 'cleaned[key] = value' branch, and Gemini would still receive an invalid declaration. Move the type override out of the loop: track whether any enum/const was coerced via a boolean flag, and force cleaned.type = 'string' after the loop finishes. This makes the fix independent of input property order. Also add curly braces around single-line ifs to satisfy check-lint (eslint(curly)) which failed on the previous commit. New reversed-order regression tests added. Co-Authored-By: Claude <[email protected]> * fix(ai): preserve Gemini enum schema types --------- Co-authored-by: leonme <[email protected]> Co-authored-by: Claude <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
Port from openclaw/openclaw#104567: Gemini requires enum metadata to be strings even when the declared tool parameter type is numeric or boolean.
Port from openclaw/openclaw#104567: Gemini requires enum metadata to be strings even when the declared tool parameter type is numeric or boolean.
Port from openclaw/openclaw#104567: Gemini requires enum metadata to be strings even when the declared tool parameter type is numeric or boolean.
Port from openclaw/openclaw#104567: Gemini requires enum metadata to be strings even when the declared tool parameter type is numeric or boolean.
fix(ai): drop non-string enums from Gemini tool schemas
The read tool declares optional as the boolean literal true. The Gemini schema cleaner turned that into {"type":"boolean","enum":["true"]}, but Google allows enum only on string types, so every Gemini and Vertex request carrying the read tool failed with HTTP 400 "enum: only allowed for STRING type". #104567 deliberately keeps the declared type so tool arguments still match local validation (#185581); changing the type to string would make Gemini send "true" and fail that check. The cleaner now keeps enums only when the declared type is string or missing, and drops the enum for other types while keeping the type. read.optional goes out as a plain boolean, and the original schema still accepts only true. Other providers' schemas are unchanged.
Evidence: a built Gateway on node:24.22.1 in secretless Docker with 14 tools including read, against a local stand-in that enforces Google's enum rule and returns the real 400 body, two runs each. On main the request failed with "...parameters.properties[optional].enum: only allowed for STRING type". With this change the request was accepted, and the stand-in's read call with optional true passed local validation and ran. The other 13 Gemini tool schemas, every string enum and the OpenAI-compatible request are byte-identical to main. Details: #196742.
Closes #196717. Thanks @yixiaoer-520 for the report.
Co-authored-by: Ayaan Zaidi <[email protected]>
fix(ai): drop non-string enums from Gemini tool schemas
The read tool declares optional as the boolean literal true. The Gemini schema cleaner turned that into {"type":"boolean","enum":["true"]}, but Google allows enum only on string types, so every Gemini and Vertex request carrying the read tool failed with HTTP 400 "enum: only allowed for STRING type". openclaw#104567 deliberately keeps the declared type so tool arguments still match local validation (openclaw#185581); changing the type to string would make Gemini send "true" and fail that check. The cleaner now keeps enums only when the declared type is string or missing, and drops the enum for other types while keeping the type. read.optional goes out as a plain boolean, and the original schema still accepts only true. Other providers' schemas are unchanged.
Evidence: a built Gateway on node:24.22.1 in secretless Docker with 14 tools including read, against a local stand-in that enforces Google's enum rule and returns the real 400 body, two runs each. On main the request failed with "...parameters.properties[optional].enum: only allowed for STRING type". With this change the request was accepted, and the stand-in's read call with optional true passed local validation and ran. The other 13 Gemini tool schemas, every string enum and the OpenAI-compatible request are byte-identical to main. Details: openclaw#196742.
Closes openclaw#196717. Thanks @yixiaoer-520 for the report.
Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes #104566.
Gemini's Function Calling API only accepts string values in
enumfields (Function Calling docs, AIP-143). When a tool schema containsenum: [1, 2, 3]orenum: [true, false], the Gemini API rejects the entire request with:Current
cleanSchemaForGeministrips unsupported keywords and rewritesconst→enum: [value]but does not coerce enum values. Any Gemini sub-agent whose full tool set contains a numeric or boolean enum (very common — priority levels, score ranges, boolean flags) fails 100 % of the time.Why This Change Was Made
Two entry points in
cleanSchemaForGeminiWithDefsproduceenumarrays:const: <value>— rewritten toenum: [<value>]at line 327.enum: [...]— currently passes through unchanged at the trailingcleaned[key] = valuebranch.Both paths need to coerce values to strings, and the schema must be retyped as
"string"since Gemini's validator only acceptsenumon string-typed schemas.What This Change Does
Adds two helpers (
coerceEnumValue/coerceEnumArray) and a dedicatedkey === "enum"case in the cleaning loop:number(finite) →String(v)boolean→"true"/"false"bigint→v.toString()string→ unchangednull/undefined/ objects / arrays / non-finite numbers → dropped from the array (also de-duplicates)enumkey is omitted entirely (matches existing behavior for emptyrequiredarrays)constis coerced through the same helper and now also retypes the containing schema to"string".Behavior Compatibility
typeof v === "string")."1"instead of1, which JavaScript comparisons and JSON parsing round-trip trivially. Most OpenClaw tool receivers already normalize scalar inputs.typeis only rewritten when the enum coercion actually happens, so puretype: "integer"schemas without enums are untouched.Evidence
Unit tests added in
clean-for-gemini.test.tscover:enum→ string enum + retyped as"string"enum→["true", "false"]enumunchanged (regression guard)const→ stringenum+ retypednull/undefineddropped, duplicates removedobject.properties.array.items.properties.enum) — matches the real-world failure path from the issueenumkey omittedLocal test run:
Verified Downstream
Applied the equivalent patch to a local install by mirroring the change into
node_modules/@openclaw/ai/dist/openai-responses-shared-*.mjsand re-ran a Gemini sub-agent invocation that had been 100 % failing:provider rejected the request schema or tool payload(400 TYPE_STRING atfunction_declarations[29].parameters...enum[0])gemini-2.5-flash-litevia an OpenAI-compatible endpointRelated Issues / Reports