Skip to content

Conversation

@cyhhao
Copy link

@cyhhao cyhhao commented Nov 26, 2025

Problem

When using tools that have injected parameters like ToolRuntime, InjectedState, or InjectedStore, Google Genai's tool conversion fails with:

PydanticInvalidForJsonSchema: Cannot generate a JsonSchema for core_schema.CallableSchema

This happens because _format_base_tool_to_function_declaration uses tool.args_schema which includes all parameters, including injected ones that contain Callable types that Pydantic cannot serialize to JSON schema.

Solution

Use tool.tool_call_schema instead of tool.args_schema. The tool_call_schema property (from langchain-core's BaseTool) already handles filtering out injected arguments, making it the correct schema to use when binding tools to models.

This is consistent with how langchain-core's convert_to_openai_function handles tools - it uses tool.tool_call_schema (see _format_tool_to_openai_function).

Testing

Tested locally with a tool using ToolRuntime parameter - the error is resolved and the tool works correctly with Google Gemini models.

Related

  • langchain-core's BaseTool.tool_call_schema property: filters out injected arguments
  • OpenAI function conversion already uses tool_call_schema

When converting tools to Google Genai function declarations, use
`tool.tool_call_schema` instead of `tool.args_schema` to properly
exclude injected arguments like `ToolRuntime`, `InjectedState`, and
`InjectedStore`.

The `args_schema` includes all parameters including injected ones,
which causes `PydanticInvalidForJsonSchema` errors when trying to
generate JSON schema for types like `ToolRuntime` that contain
`Callable` fields.

The `tool_call_schema` property (from langchain-core BaseTool) already
handles filtering out injected arguments, making it the correct schema
to use when binding tools to models.

Fixes issue where tools using `ToolRuntime` parameter fail with:
`Cannot generate a JsonSchema for core_schema.CallableSchema`
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.

1 participant