Skip to content

[Bug]: Anthropic model calls with Tools : Input should be a valid dictionary #11196

@simonljn

Description

@simonljn

What happened?

Using litelllm image v1.71.1-stable for litellm proxy

I have an error with Anthropic model calls with Tools that i don't have on openai calls for the same request :

'litellm.BadRequestError: AnthropicException - {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.0.tool_use.input: Input should be a valid dictionary"}}. Received Model Group=x-anthropic-x\n'

Sample code :

import openai from "openai";

const client = new openai({
  apiKey: "xx",
  baseURL: "https://litellm-xx",
});

async function main() {
  const out = await client.chat.completions.create({
    messages: [
      {
        content: "search : foo",
        role: "user",
      },
      {
        role: "assistant",
        tool_calls: [
          {
            function: {
              arguments: '"{\\"query\\": \\"foo\\"}"',
              name: "WebSearch",
            },
            id: "toolu_01LaSrYM7jQ4snmb3h4cb2A2",
            type: "function",
          },
        ],
      },
      {
        content: "...  foo search response ....",
        role: "tool",
        tool_call_id: "toolu_01LaSrYM7jQ4snmb3h4cb2A2",
      },
      {
        content: "search : bar",
        role: "user",
      },
    ],
    model: "x-anthropic-x",
    tool_choice: "auto",
    tools: [
      {
        function: {
          description: "Make a search",
          name: "Search",
          parameters: {
            properties: {
              query: {
                description: "The search query",
                type: "string",
              },
            },
            required: ["query"],
            type: "object",
          },
        },
        type: "function",
      },
    ],
  });

  console.log(out);
}

main();

Relevant log output

Are you a ML Ops Team?

No

What LiteLLM version are you on ?

v1.71.1

Twitter / LinkedIn details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions