Skip to content

fix(llm): coerce all non-string enum types to string for Gemini#28412

Closed
kagura-agent wants to merge 1 commit into
anomalyco:devfrom
kagura-agent:fix/gemini-enum-non-string-type
Closed

fix(llm): coerce all non-string enum types to string for Gemini#28412
kagura-agent wants to merge 1 commit into
anomalyco:devfrom
kagura-agent:fix/gemini-enum-non-string-type

Conversation

@kagura-agent
Copy link
Copy Markdown
Contributor

@kagura-agent kagura-agent commented May 20, 2026

Issue for this PR

Closes #28397

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Google's Gemini API only allows .enum on STRING type properties. The existing gemini-tool-schema.ts sanitizer coerces integer/number enum properties to string, but misses boolean and other non-string types — causing the API to reject tool declarations with: .enum: only allowed for STRING type.

The fix generalizes the type guard from checking integer || number to checking type !== "string", so any non-string typed property with an enum gets coerced. This is safe because the preceding line already stringifies all enum values.

How did you verify your code works?

Extended the existing Gemini test to include a boolean enum property and confirmed it gets coerced to string type. All 11 Gemini tests pass.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Google's Gemini API rejects `.enum` on non-STRING type properties.
The existing sanitizer handled integer/number but not boolean or
other types. Generalize the guard to coerce any non-string typed
enum property to string, matching the existing pattern of
stringifying enum values.

Fixes anomalyco#28397
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. contributor and removed needs:compliance This means the issue will auto-close after 2 hours. labels May 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@kagura-agent
Copy link
Copy Markdown
Contributor Author

Friendly ping — this has been open for a week. The fix coerces non-string enum values (numbers, booleans) to strings before sending to Gemini, preventing the 400 error described in #28397. Happy to adjust if needed.

@kagura-agent
Copy link
Copy Markdown
Contributor Author

Hi — friendly check-in on this one. It's been about a week without review. Let me know if any changes are needed or if this approach works. Happy to adjust! 🙏

@kagura-agent
Copy link
Copy Markdown
Contributor Author

Hi 👋 Friendly ping — this has been open for about 9 days without review. Let me know if there's anything I should adjust or if the approach needs rethinking. Happy to rebase if needed!

@kagura-agent
Copy link
Copy Markdown
Contributor Author

Closing this as it's been 10 days with three pings and no review. The fix coerces non-string enum types to string before passing to Gemini. Happy to reopen if there's interest — feel free to ping me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google Provider - .enum: only allowed for STRING type

1 participant