Skip to content

fix(llm): drop empty-string enum members for Gemini tool schemas - #46676

Closed
dotCipher wants to merge 3 commits into
anomalyco:devfrom
dotCipher:gemini-empty-enum
Closed

dotCipher wants to merge 3 commits into
anomalyco:devfrom
dotCipher:gemini-empty-enum

Conversation

@dotCipher

@dotCipher dotCipher commented Sep 1, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #33316

Type of change

  • Bug fix

What does this PR do?

Gemini's function-calling schema validator rejects any enum member that's an empty string (enum[0]: cannot be empty). Some MCP servers use "" as a sentinel for "unset"/"clear this field" on a string enum, which is valid JSON Schema but breaks every turn on a Gemini model once that server is connected — Gemini validates the whole tools[] array up front, not just the tool being called. That's what #33316 hit (link.any_of[0].enum[0] from a Canva MCP tool), though it got triaged as a Canva/$ref-specific issue at the time.

packages/llm/src/protocols/utils/gemini-tool-schema.ts already sanitizes several Gemini-incompatible schema shapes for MCP tools. This adds one more: strip "" out of enum arrays (including ones nested inside anyOf/oneOf/allOf), and drop the enum constraint entirely if that empties it.

How did you verify your code works?

Added a test to packages/llm/test/tool-schema-projection.test.ts covering a plain enum with a "" sentinel, the same sentinel nested in an anyOf nullable branch, and an enum that's only [""]. Ran the full packages/llm test suite (299 pass, 0 fail) and bun run typecheck, both clean.

Screenshots / recordings

N/A, no UI change.

Checklist

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

Google AI Studio rejects any function-declaration enum member that
stringifies to "", e.g.:

  GenerateContentRequest.tools[0].function_declarations[N].parameters
    .properties[field].enum[0]: cannot be empty

MCP servers commonly model an "unset"/"clear this field" option as a
literal "" enum member (distinct from omitting the argument, which
means "leave unchanged"). That's valid JSON Schema and works fine
against Anthropic/OpenAI, but Gemini validates the entire tools[]
array up front on every generateContent call, so a single tool with
this shape breaks every request on that turn, not just calls to the
offending tool.

Strip "" out of enum arrays in the Gemini tool-schema sanitizer (plain
enums and enums nested inside anyOf/oneOf/allOf branches, since
sanitizeNode already recurses into those). If stripping empties the
enum entirely, drop the constraint and fall back to the bare type.

Reproduced against a real-world MCP server (personas_create /
personas_update / personas_add_detail tools using "" as an explicit
clear-field sentinel) that reliably 400s every Gemini turn while
connected.
@github-actions github-actions Bot added needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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.

Canva MCP: Tool registration fails with schema validation error "enum[0]: cannot be empty" despite successful authentication

1 participant