Skip to content

google payloads with anthropic models don't work with tool calls #172

@knjiang

Description

@knjiang

the original payload for toolCallRequest with google is https://github.com/braintrustdata/lingua/blob/main/payloads/cases/simple.ts#L405C1-L432C7:

{
    google: {
      contents: [
        {
          role: "user",
          parts: [{ text: "What's the weather like in San Francisco?" }],
        },
      ],
      tools: [
        {
          functionDeclarations: [
            {
              name: "get_weather",
              description: "Get the current weather for a location",
              parameters: {
                type: Type.OBJECT,
                properties: {
                  location: {
                    type: Type.STRING,
                    description: "The city and state, e.g. San Francisco, CA",
                  },
                },
                required: ["location"],
              },
            },
          ],
        },
      ],
    },
}

example of the google payload -> transformed anthropic request that results in an API error from anthropic:

{
  "max_tokens": 4096,
  "messages": [
    {
      "content": "What's the weather like in San Francisco?",
      "role": "user",
    },
  ],
  "model": "claude-sonnet-4-5-20250929",
  "tools": [
    {
      "description": "Get the current weather for a location",
      "input_schema": {
        "properties": {
          "location": {
            "description": "The city and state, e.g. San Francisco, CA",
            "type": "string",
          },
        },
        "required": [
          "location",
        ],
        "type": "object",
      },
      "name": "get_weather",
    },
  ],
}

the anthropic response when we trying translating google payloads to anthropic by using an anthropic model -> https://github.com/braintrustdata/lingua/blob/main/payloads/transforms/google_to_anthropic/toolCallRequest.json

{
  "error": "400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"tools.0.custom.input_schema.type: Input should be 'object'\"},\"request_id\":\"req_011CZbYt6Kw83ZmAdNZQzYZA\"}",
  "name": "Error"
}

this specific issue should cover the following cases from transform_errors.json:

  "google_to_anthropic": {
    "toolCallRequest": "Anthropic rejected: tool input_schema type must be 'object', not null",
    "toolChoiceRequiredParam": "Anthropic rejected: tool input_schema type must be 'object', not null",
    "toolChoiceAutoParam": "Anthropic rejected: tool input_schema type must be 'object', not null",
    "toolChoiceAnyParam": "Anthropic rejected: tool input_schema type must be 'object', not null",
    "toolChoiceNoneParam": "Anthropic rejected: tool input_schema type must be 'object', not null",
    "toolModeValidatedParam": "Anthropic rejected: tool input_schema type must be 'object', not null"
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions