Skip to content

fix(gemini): coerce boolean JSON-schema sub-schemas for genai compatibility#3634

Merged
Sayt-0 merged 1 commit into
docker:mainfrom
EronWright:fix/gemini-boolean-schema
Jul 15, 2026
Merged

fix(gemini): coerce boolean JSON-schema sub-schemas for genai compatibility#3634
Sayt-0 merged 1 commit into
docker:mainfrom
EronWright:fix/gemini-boolean-schema

Conversation

@EronWright

Copy link
Copy Markdown
Contributor

Problem

MCP tool input schemas are full JSON Schema, where any sub-schema position — a properties value, items, an anyOf entry, etc. — may be a bare boolean: true = "any value validates", false = "nothing validates". Gemini's Schema type is an OpenAPI-3.0 subset with no boolean-schema form, so genai unmarshals every sub-schema into a *genai.Schema and hard-fails on a JSON boolean:

json: cannot unmarshal bool into Go struct field Schema.properties of type genai.Schema

This kills the run before the first model call. A Go any/interface{} field in an MCP tool's input struct is the common source: schema generators such as google/jsonschema-go (used by mcp-go and the official MCP Go SDK) render an unconstrained field as the boolean true schema, so any MCP server exposing such a tool is otherwise unusable with Gemini.

Fix

Adds normalizeBooleanSchemas to the existing ConvertParametersToSchema normalization pipeline (alongside the type-array and enum normalizers already there): recursively coerce boolean sub-schemas to an empty object schema {} in every schema-bearing position (properties/items/anyOf/…), leaving additionalProperties booleans untouched (genai ignores the keyword). {} preserves "any value" while staying parseable by genai.

Tests

Adds pkg/model/provider/gemini/schema_boolean_test.go:

  • TestConvertParametersToSchema_BooleanSubSchema — a schema with boolean sub-schemas (the any-field shape) now converts without error.
  • TestNormalizeBooleanSchemas — booleans coerced in nested positions; additionalProperties booleans preserved.

…bility

MCP tool input schemas are full JSON Schema, where any sub-schema position
(a "properties" value, "items", an "anyOf" entry, ...) may be a bare boolean:
true = "any value validates", false = "nothing validates". Gemini's Schema type
is an OpenAPI 3.0 subset with no boolean-schema form, so genai unmarshals every
sub-schema into a *genai.Schema and hard-fails on a JSON boolean:

  json: cannot unmarshal bool into Go struct field Schema.properties of type genai.Schema

A Go any/interface{} field in an MCP tool's input struct is the common source:
schema generators such as google/jsonschema-go render an unconstrained field as
the boolean `true` schema, so any MCP server exposing such a tool is otherwise
unusable with Gemini.

Add normalizeBooleanSchemas to the ConvertParametersToSchema pipeline, alongside
the existing type-array and enum normalizers: recursively coerce boolean
sub-schemas to an empty object schema {} in every schema-bearing position,
leaving additionalProperties booleans untouched (genai ignores the keyword).

Signed-off-by: Eron Wright <eronwright@gmail.com>
@EronWright EronWright requested a review from a team as a code owner July 14, 2026 03:32
@aheritier aheritier added area/providers/gemini Google Gemini provider support kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Jul 14, 2026
@Sayt-0 Sayt-0 merged commit 85b497a into docker:main Jul 15, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/providers/gemini Google Gemini provider support kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants