{"record":{"id":"f2ee2b2b47f5c9ac","repo":"continuedev/continue","slug":"failed-to-convert-tool-to-gemini-function-definiti-f2ee2b","errorCode":null,"errorMessage":"Failed to convert tool to gemini function definition. Skipping: ${JSON.stringify(tool, null, 2)}","messagePattern":"Failed to convert tool to gemini function definition\\. Skipping: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/openai-adapters/src/apis/Gemini.ts","lineNumber":264,"sourceCode":"      // if there is a system message, reformat it for Gemini API\n      ...(sysMsg &&\n        !isV1API && {\n          systemInstruction: { parts: [{ text: sysMsg.content }] },\n        }),\n    };\n\n    if (!isV1API) {\n      // Convert and add tools if present\n      if (oaiBody.tools?.length) {\n        // Choosing to map all tools to the functionDeclarations of one tool\n        // Rather than map each tool to its own tool + functionDeclaration\n        // Same difference\n        const functions: GeminiToolFunctionDeclaration[] = [];\n        oaiBody.tools.forEach((tool) => {\n          try {\n            functions.push(convertOpenAIToolToGeminiFunction(tool));\n          } catch (e) {\n            console.warn(\n              `Failed to convert tool to gemini function definition. Skipping: ${JSON.stringify(tool, null, 2)}`,\n            );\n          }\n        });\n\n        if (functions.length) {\n          finalBody.tools = [\n            {\n              functionDeclarations: functions,\n            },\n          ];\n        }\n      }\n    }\n\n    return finalBody;\n  }\n","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/continuedev/continue/blob/5522c6f44ca0ac3528b37244818fbfa39b5af470/packages/openai-adapters/src/apis/Gemini.ts#L246-L282","documentation":"In _convertBody, each OpenAI tool definition is converted to a Gemini function declaration via convertOpenAIToolToGeminiFunction. If a tool's schema cannot be converted (throws), the individual tool is skipped with this warning — including a JSON dump of the tool — and the remaining tools still get sent.","triggerScenarios":"Passing tools with JSON Schemas Gemini rejects: unsupported JSON Schema keywords/complex types, a function with no valid parameters schema, or a malformed tool object missing name/parameters.","commonSituations":"Forwarding OpenAI-format tool definitions (draft-07 style with $ref/oneOf/allOf or nested required) to Gemini; generating tools from Zod/TypeBox without sanitizing to Gemini's strict subset.","solutions":["Inspect the logged JSON dump to identify which tool failed","Simplify the parameters JSON Schema to Gemini's supported subset (type: object, properties, required, enum; avoid $ref/allOf/oneOf at top level)","Ensure each tool has a valid name and a parameters object of JSON Schema type \"object\"","Test each tool with convertOpenAIToolToGeminiFunction in isolation before batching"],"exampleFix":"// before\n{ type: \"function\", function: { name: \"f\", parameters: { anyOf: [{type:\"string\"},{type:\"number\"}] } } }\n\n// after\n{ type: \"function\", function: { name: \"f\", parameters: { type: \"object\", properties: { v: { type: \"string\" } } } } }","handlingStrategy":"validation","validationCode":"const t = tool.function;\nif (!t?.name || t.parameters?.type !== \"object\") {\n  throw new Error(`Tool ${t?.name} has an unsupported schema for Gemini`);\n}","typeGuard":"const isGeminiSafeTool = (t: any): boolean =>\n  t?.type === \"function\" &&\n  typeof t.function?.name === \"string\" &&\n  (t.function.parameters === undefined || t.function.parameters?.type === \"object\");","tryCatchPattern":null,"preventionTips":["Restrict parameter schemas to Gemini's subset (object/properties/required/enum)","Avoid $ref/allOf/oneOf in tool schemas sent to Gemini","Test each tool conversion individually when adding new tools"],"tags":["gemini","tool-calls","json-schema","openai-compat"],"backgroundTag":"json-schema-conversion-failed","analyzedSha":"5522c6f44ca0ac3528b37244818fbfa39b5af470","analyzedAt":"2026-08-27T11:28:54.683Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}