Skip to content

fix(core): normalize JSON Schema nullable type arrays in toGeminiSchema - #45

Open
mv2sa wants to merge 2 commits into
cortexkit:mainfrom
mv2sa:fix/gemini-nullable-type-array
Open

mv2sa wants to merge 2 commits into
cortexkit:mainfrom
mv2sa:fix/gemini-nullable-type-array

Conversation

@mv2sa

@mv2sa mv2sa commented Oct 25, 2026

Copy link
Copy Markdown

Fixes #44

Summary

toGeminiSchema already normalizes anyOf / oneOf null unions into { type, nullable: true }, but JSON Schema nullable type arrays (type: ["string", "null"]) reached typeof inputSchema.type === 'string' as an array and had their type dropped. Tools that declare nullable arguments via type arrays (such as OpenCode 2.x tools with type: ["string", "null"]) then failed on Gemini models with HTTP 400.

Changes

  • Add normalizeNullableTypeArray in packages/core/src/transform/gemini.ts after mergeSchemaAllOf to normalize:
    • 2-element nullable type arrays (["string", "null"], ["null", "integer"], etc., case-insensitive and deduplicated) to { type: "<type>", nullable: true }
    • 1-element arrays (["string"] -> type: "string", ["null"] -> type: "null")
    • Nested object properties, array items, and allOf-merged schemas
  • Leave genuine multi-type arrays (["string", "number"]) and unknown type entries untouched so existing provider validation handles them without misclassifying schema errors.
  • Add unit coverage in packages/core/src/transform/gemini.test.ts.

Verification

  • bun test --isolate packages/core/src/transform/gemini.test.ts (166 pass, 0 fail)
  • bun run --cwd packages/core typecheck (0 errors)
  • bun x @biomejs/biome check packages/core/src/transform/gemini.ts packages/core/src/transform/gemini.test.ts
  • Live tool-call round-trips with explicit null arguments on antigravity-gemini-3.8-flash and antigravity-gemini-4-argon.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

Comment thread packages/core/src/transform/gemini.ts
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.

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

1 participant