kimi-cli icon indicating copy to clipboard operation
kimi-cli copied to clipboard

[Bug]: Google GenAI provider fails with extra_forbidden for tool parameters containing $schema

Open XYenon opened this issue 10 months ago • 2 comments

What version of Kimi Code CLI is running?

1.2

Which open platform/subscription were you using?

google_genai

Which model were you using?

gemini-3-pro-preview

What platform is your computer?

Linux

What issue are you seeing?

When using Exa MCP (https://mcp.exa.ai/mcp) or other tools that provide standard JSON Schema parameters, a validation error occurs during the tool calling phase:

Unexpected error: 1 validation error for FunctionDeclaration
parameters.$schema
  Extra inputs are not permitted [type=extra_forbidden, input_value='http://json-schema.org/draft-07/schema#', input_type=str]
    For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden

This error is caused by the google-genai SDK's Pydantic model enforcing strict validation on the FunctionDeclaration parameters field, rejecting the $schema metadata field.

What steps can reproduce the bug?

  1. Configure the google_genai provider.
  2. Add Exa MCP: kimi mcp add exa https://mcp.exa.ai/mcp.
  3. Execute any command triggering a search (e.g., Search for latest AI news using exa).
  4. The error occurs.

Minimal Reproduction Code (using uv):

uv run --no-project --python 3.12 --with google-genai --with pydantic python -c "
from google.genai.types import FunctionDeclaration
try:
    FunctionDeclaration(
        name='test',
        description='test',
        parameters={'$schema': 'http://json-schema.org/draft-07/schema#', 'type': 'object'}
    )
except Exception as e:
    print(e)
"

What is the expected behavior?

Tool calls should proceed successfully. The provider should strip unsupported JSON Schema keywords (like $schema) from the parameters before passing them to the google-genai SDK.

XYenon avatar Jan 27 '26 17:01 XYenon

I'll try to fix it.

xiaoju111a avatar Jan 28 '26 03:01 xiaoju111a

The tool_to_google_genai() function passes tool.parameters directly to FunctionDeclaration, and the google-genai SDK's Pydantic model rejects $schema and similar JSON Schema metadata fields. Fix: strip unsupported keys ($schema, $id, $ref, $comment, definitions, $defs) before passing to the SDK.

Br1an67 avatar Mar 17 '26 06:03 Br1an67