Skip to content

toGeminiSchema drops type on JSON Schema nullable type arrays (type: ["string", "null"]), causing 400 on Gemini tool calls #44

Open

Description

@mv2sa

Problem

When a tool parameter uses a JSON Schema draft-07 / 2020-12 nullable type array such as type: ["string", "null"] (or ["integer", "null"], ["boolean", "null"], etc.), toGeminiSchema in packages/core/src/transform/gemini.ts checks typeof inputSchema.type === 'string'. Because inputSchema.type is an array, schemaType evaluates to undefined and the emitted Gemini schema drops type completely while keeping description / enum / properties.

OpenCode 2.x built-in and MCP tools emit nullable parameters in this form (for example planId: { type: ["string", "null"] }). When sent to Cloud Code for Gemini models (antigravity-gemini-3.8-flash, antigravity-gemini-4-argon), the request fails with HTTP 400 INVALID_ARGUMENT due to the typeless parameter definition.

Reproduction

Input tool schema property:

{
  "type": ["string", "null"],
  "description": "The plan a note or todo belongs to; null unlinks"
}

Current toGeminiSchema output (missing type and nullable):

{
  "description": "The plan a note or todo belongs to; null unlinks"
}

Expected toGeminiSchema output:

{
  "type": "STRING",
  "nullable": true,
  "description": "The plan a note or todo belongs to; null unlinks"
}

Fix

Normalize single-type nullable arrays (["string", "null"], ["null", "integer"], single-element ["string"], ["null"], and case/duplicate variants) into { type: "<non-null>", nullable: true } before reading inputSchema.type, while leaving multi-type unions (["string", "number"]) untouched for existing validation.

Activity

  1. agauth-alfonso commented on Oct 26, 2026

    @agauth-alfonso

    Thanks for the clear report and the fix PR. We're reproducing it against the current code and will reply here with the result.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions