Skip to content

fix(provider): infer type 'object' for schemas with properties but missing type in Gemini sanitization#13150

Open
ChickenBreast-ky wants to merge 1 commit intoanomalyco:devfrom
ChickenBreast-ky:fix/gemini-schema-missing-type
Open

fix(provider): infer type 'object' for schemas with properties but missing type in Gemini sanitization#13150
ChickenBreast-ky wants to merge 1 commit intoanomalyco:devfrom
ChickenBreast-ky:fix/gemini-schema-missing-type

Conversation

@ChickenBreast-ky
Copy link
Contributor

Summary

Follow-up to #11888. sanitizeGemini strips properties/required from non-object types, but misses the case where type is entirely undefined (undefined).

Fixes #13148

Problem

The current check:

if (result.type && result.type !== "object") {
  delete result.properties
  delete result.required
}

When type is undefined, result.type && ... short-circuits to false, so properties/required are not removed. MCP tools like Notion MCP define schemas where type is omitted but properties/required are present (valid per JSON Schema spec as implicit objects):

{
  "data": {
    "description": "The data required for updating a page",
    "properties": { "page_id": { "type": "string" } },
    "required": ["page_id"]
  }
}

This causes:

Bad Request: GenerateContentRequest.tools[0].function_declarations[90].parameters.properties[data].properties: only allowed for OBJECT type

Solution

Infer type: "object" when properties or required exist but type is missing, before the existing non-object stripping logic:

if (!result.type && (result.properties || result.required)) {
  result.type = "object"
}

Changes

  • packages/opencode/src/provider/transform.ts: Added 4 lines to infer missing type
  • packages/opencode/test/provider/transform.test.ts: Added 2 test cases for missing type inference

Related Issues

…ssing type in Gemini sanitization

Follow-up to anomalyco#11888. sanitizeGemini strips properties/required from
non-object types, but misses the case where type is entirely undefined.
MCP tools like Notion define schemas with properties/required but no
type field, causing Gemini API 400 errors.

This fix infers type 'object' when properties or required exist but
type is missing, per JSON Schema's implicit object semantics.

Fixes anomalyco#13148
@github-actions
Copy link
Contributor

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

No duplicate PRs found

@ChickenBreast-ky
Copy link
Contributor Author

CI note: e2e (windows) failure is unrelated — zod cache ENOENT + session file path issue on Windows CI environment. unit (linux) (which covers this change) passed ✅

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.

[bug] Gemini schema sanitization misses properties/required when type is undefined

1 participant

Comments