genkit icon indicating copy to clipboard operation
genkit copied to clipboard

[Python] google-genai: send tool schemas as parameters_json_schema / response_json_schema

Open hilariie opened this issue 3 weeks ago • 0 comments

Tool input and output schemas are converted to Gemini Schema objects before they're sent. The converter drops what it can't express: a required property that refers back to a model containing it, a recursive anyOf branch, an array without usable items. Tool schemas from MCP servers, which the MCP plugin passes through as is, hit these cases often. Since #6969 each drop logs a warning, but the tool is still sent with a weaker schema than the one it declared.

google-genai 2.21 has FunctionDeclaration.parameters_json_schema and response_json_schema, which take raw JSON Schema. Structured output already sends response_json_schema by default, with legacy_response_schema to opt out. Sending tool schemas the same way would pass them through unchanged and make most of the converter's tool-side edge cases go away.

Things to work out:

  • A non-object input schema is wrapped in an object with a single property. Local $refs, including #/$defs/..., then point at the wrong node, so they need rewriting and $defs needs moving to the wrapper.
  • Whether to wrap is decided from the converted type today. On a raw schema it has to come from type, which can be a list, or absent on an anyOf node.
  • What the API accepts in parameters_json_schema (recursive $ref, $schema, additionalProperties) on both the Gemini API and Vertex has to be checked live.
  • A schema that's trimmed and sent today would be sent whole, and could get a 400 instead. Likely needs an opt-out like legacy_response_schema.

JS and Go both still send converted parameters for tools.

hilariie avatar Nov 10 '26 09:11 hilariie