Skip to content

fix(gemini): prevent gemini incompatibility with some tools - #31877

Merged
rekram1-node merged 1 commit into
anomalyco:devfrom
Killusions:fix/prevent-gemini-incompatibility-with-some-tools-in-gemini
Jun 11, 2026
Merged

fix(gemini): prevent gemini incompatibility with some tools#31877
rekram1-node merged 1 commit into
anomalyco:devfrom
Killusions:fix/prevent-gemini-incompatibility-with-some-tools-in-gemini

Conversation

@Killusions

@Killusions Killusions commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #19276

Type of change

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

What does this PR do?

Fixes a type schema incompatibility with Gemini and some tools/MCPs (occured through GitHub Copilot).

How did you verify your code works?

Tested locally.

Screenshots / recordings

None

Checklist

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

⚒️ with ❤️ by @siemens

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found a potentially related PR:

Related PR:

This PR appears related as it also addresses Gemini schema issues. While #31877 focuses on preventing Gemini incompatibility with tools, PR #27641 specifically handles sanitizing Gemini schema references, which could be addressing a similar underlying compatibility problem with Gemini's type schema handling.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

@Killusions
Killusions force-pushed the fix/prevent-gemini-incompatibility-with-some-tools-in-gemini branch from 2ed7b0d to 99504d1 Compare June 11, 2026 11:43
@max-wittig

Copy link
Copy Markdown

Looks nice! Is this something you could look at to get Gemini working with opencode? @thdxr

@rekram1-node

Copy link
Copy Markdown
Collaborator

I don't think this matches how ai-sdk/google behaves

@rekram1-node

Copy link
Copy Markdown
Collaborator
The PR comment says plain @ai-sdk/google “rewrites these,” but the PR does not implement the same rewrite.
@ai-sdk/google converts:
{ "type": ["number", "string"] }
into:
{
  "anyOf": [
    { "type": "number" },
    { "type": "string" }
  ]
}
The PR converts it into:
{ "type": "number" }
It simply keeps the first non-null type, losing "string".

@Killusions
Killusions force-pushed the fix/prevent-gemini-incompatibility-with-some-tools-in-gemini branch from 99504d1 to 35581b1 Compare June 11, 2026 15:45
@Killusions

Copy link
Copy Markdown
Contributor Author

@rekram1-node tried to align it more to how the adapter works

@rekram1-node

rekram1-node commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

@Killusions thx, also do u mind adding a test case for this by chance? Im sure there are prolly some more cases we need to handle better too but for now just adding a new test will be nice

Some MCPs fail with Gemini
(at least via GitHub Copilot)

Close anomalyco#19276
@Killusions
Killusions force-pushed the fix/prevent-gemini-incompatibility-with-some-tools-in-gemini branch from 35581b1 to 612607c Compare June 11, 2026 15:59
@Killusions

Copy link
Copy Markdown
Contributor Author

@rekram1-node Added one

@rekram1-node
rekram1-node merged commit 2e71292 into anomalyco:dev Jun 11, 2026
8 checks passed
@max-wittig

Copy link
Copy Markdown

Amazing! Thank you very much for all the work you're doing here!

isaacfinnegan pushed a commit to isaacfinnegan/whispercode that referenced this pull request Jun 15, 2026
leduyphuc1702 pushed a commit to leduyphuc1702/opencode-workflow that referenced this pull request Jun 16, 2026
davidgut1982 pushed a commit to davidgut1982/opencode that referenced this pull request Jun 19, 2026
markjaquith pushed a commit to markjaquith/opencode that referenced this pull request Jun 23, 2026
BenGu3 pushed a commit to BenGu3/opencode that referenced this pull request Jun 27, 2026
panyw5 pushed a commit to panyw5/opencode that referenced this pull request Jul 3, 2026
teknium1 added a commit to NousResearch/hermes-agent that referenced this pull request Jul 7, 2026
…branches

Port from anomalyco/opencode#31877: JSON Schema type arrays like
["number","string"] (common in MCP tool schemas) were collapsed to the
first non-null type, silently dropping every other branch. Several
tool-call backends reject the array form outright — llama.cpp's grammar
generator and Gemini via OpenAI-compatible transports (e.g. GitHub
Copilot proxying to Gemini) 400 on it.

_sanitize_node now mirrors @ai-sdk/google: a single non-null type stays
type:X (+nullable if null was present), multiple non-null types become
an anyOf of single-type schemas so no branch is lost, and an all-null
array becomes type:null. Single-null collapse is unchanged.

Verified nested (object props, array items) survive the full sanitize
pipeline — combinator stripping is top-level-only and nullable-union
collapse only fires on single-survivor unions, so multi-type anyOf is
left intact.
teknium1 added a commit to NousResearch/hermes-agent that referenced this pull request Jul 7, 2026
…branches

Port from anomalyco/opencode#31877: JSON Schema type arrays like
["number","string"] (common in MCP tool schemas) were collapsed to the
first non-null type, silently dropping every other branch. Several
tool-call backends reject the array form outright — llama.cpp's grammar
generator and Gemini via OpenAI-compatible transports (e.g. GitHub
Copilot proxying to Gemini) 400 on it.

_sanitize_node now mirrors @ai-sdk/google: a single non-null type stays
type:X (+nullable if null was present), multiple non-null types become
an anyOf of single-type schemas so no branch is lost, and an all-null
array becomes type:null. Single-null collapse is unchanged.

Verified nested (object props, array items) survive the full sanitize
pipeline — combinator stripping is top-level-only and nullable-union
collapse only fires on single-survivor unions, so multi-type anyOf is
left intact.
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…branches

Port from anomalyco/opencode#31877: JSON Schema type arrays like
["number","string"] (common in MCP tool schemas) were collapsed to the
first non-null type, silently dropping every other branch. Several
tool-call backends reject the array form outright — llama.cpp's grammar
generator and Gemini via OpenAI-compatible transports (e.g. GitHub
Copilot proxying to Gemini) 400 on it.

_sanitize_node now mirrors @ai-sdk/google: a single non-null type stays
type:X (+nullable if null was present), multiple non-null types become
an anyOf of single-type schemas so no branch is lost, and an all-null
array becomes type:null. Single-null collapse is unchanged.

Verified nested (object props, array items) survive the full sanitize
pipeline — combinator stripping is top-level-only and nullable-union
collapse only fires on single-survivor unions, so multi-type anyOf is
left intact.
justemu pushed a commit to justemu/hermes-agent that referenced this pull request Jul 18, 2026
…branches

Port from anomalyco/opencode#31877: JSON Schema type arrays like
["number","string"] (common in MCP tool schemas) were collapsed to the
first non-null type, silently dropping every other branch. Several
tool-call backends reject the array form outright — llama.cpp's grammar
generator and Gemini via OpenAI-compatible transports (e.g. GitHub
Copilot proxying to Gemini) 400 on it.

_sanitize_node now mirrors @ai-sdk/google: a single non-null type stays
type:X (+nullable if null was present), multiple non-null types become
an anyOf of single-type schemas so no branch is lost, and an all-null
array becomes type:null. Single-null collapse is unchanged.

Verified nested (object props, array items) survive the full sanitize
pipeline — combinator stripping is top-level-only and nullable-union
collapse only fires on single-survivor unions, so multi-type anyOf is
left intact.
avion23 pushed a commit to avion23/opencode that referenced this pull request Jul 20, 2026
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…branches

Port from anomalyco/opencode#31877: JSON Schema type arrays like
["number","string"] (common in MCP tool schemas) were collapsed to the
first non-null type, silently dropping every other branch. Several
tool-call backends reject the array form outright — llama.cpp's grammar
generator and Gemini via OpenAI-compatible transports (e.g. GitHub
Copilot proxying to Gemini) 400 on it.

_sanitize_node now mirrors @ai-sdk/google: a single non-null type stays
type:X (+nullable if null was present), multiple non-null types become
an anyOf of single-type schemas so no branch is lost, and an all-null
array becomes type:null. Single-null collapse is unchanged.

Verified nested (object props, array items) survive the full sanitize
pipeline — combinator stripping is top-level-only and nullable-union
collapse only fires on single-survivor unions, so multi-type anyOf is
left intact.
3kaiu pushed a commit to 3kaiu/opencode-x that referenced this pull request Jul 31, 2026
banlanzs pushed a commit to banlanzs/opencode that referenced this pull request Aug 6, 2026
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…branches

Port from anomalyco/opencode#31877: JSON Schema type arrays like
["number","string"] (common in MCP tool schemas) were collapsed to the
first non-null type, silently dropping every other branch. Several
tool-call backends reject the array form outright — llama.cpp's grammar
generator and Gemini via OpenAI-compatible transports (e.g. GitHub
Copilot proxying to Gemini) 400 on it.

_sanitize_node now mirrors @ai-sdk/google: a single non-null type stays
type:X (+nullable if null was present), multiple non-null types become
an anyOf of single-type schemas so no branch is lost, and an all-null
array becomes type:null. Single-null collapse is unchanged.

Verified nested (object props, array items) survive the full sanitize
pipeline — combinator stripping is top-level-only and nullable-union
collapse only fires on single-survivor unions, so multi-type anyOf is
left intact.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini 3.1 Pro API returns 400 error due to tool schema incompatibility

3 participants