OpenAI with LiteLLM tool usage throws error that doesnt appear when using Gemini or Claude
I have an MCP toolset that I am using which doesnt throw any errors when using Gemini or Claude but when using Openai it gives me this error
litellm.BadRequestError: OpenAIException - Invalid schema for function 'scrape_webpage': 'BOOLEAN' is not valid under any of the given schemas.
Some other times its 'STRING' as well
Any one else facing this same issue
same for me!
litellm.exceptions.BadRequestError: litellm.BadRequestError: OpenAIException - Invalid schema for function 'create_data': 'STRING' is not valid under any of the given schemas.
Passing in a Pydantic Schema wrapped on BaseModel
Getting the same error. Has anyone found any solution for it ?
For me, I simply "unwrapped" the Pydantic Model I was originally passing on to the function, so instead of doing
class InputParams(BaseModel):
par1:str
par2:int
async def tool1(InputParams):
# do stuff
I simply do:
async def tool1(par1:str, par2:int):
# do stuff
I know that other frameworks can handle Pydantic out of the box but apparently, google adk still cant so this is my only work around
Hi @kanlanc, thanks for reporting this issue and thanks to everyone participating! Not sure if I understand correctly. I tried the following code, which seems to be working fine:
import random
from google.adk.agents.llm_agent import Agent
from google.adk.models.lite_llm import LiteLlm
from pydantic import BaseModel
# MODEL_ID = "gemini/gemini-2.5-pro"
# MODEL_ID = "openrouter/" + "anthropic/claude-sonnet-4"
MODEL_ID = "openrouter/" + "openai/gpt-4.1-mini"
class DiceRoll(BaseModel):
"""A class to represent a dice roll."""
sides: int
def roll_die(dice_roll: DiceRoll) -> int:
"""Roll a die and return the rolled result.
Args:
dice_roll: The dice roll to roll.
Returns:
The result of the dice roll.
"""
return random.randint(1, dice_roll["sides"])
root_agent = Agent(
model=LiteLlm(model=MODEL_ID),
name="hello_world_litellm_agent",
description=(
"hello world agent that can roll a dice of 8 sides and check prime"
" numbers."
),
instruction="""
You roll dice and answer questions about the outcome of the dice rolls.
You can roll dice of different sizes.
You can use multiple tools in parallel by calling functions in parallel(in one request and in one round).
It is ok to discuss previous dice roles, and comment on the dice rolls.
When you are asked to roll a die, you must call the roll_die tool with the number of sides. Be sure to pass in an integer. Do not pass in a string.
You should never roll a die on your own.
When checking prime numbers, call the check_prime tool with a list of integers. Be sure to pass in a list of integers. You should never pass in a string.
You should not check prime numbers before calling the tool.
When you are asked to roll a die and check prime numbers, you should always make the following two function calls:
1. You should first call the roll_die tool to get a roll. Wait for the function response before calling the check_prime tool.
2. After you get the function response from roll_die tool, you should call the check_prime tool with the roll_die result.
2.1 If user asks you to check primes based on previous rolls, make sure you include the previous rolls in the list.
3. When you respond, you must include the roll_die result from step 1.
You should always perform the previous 3 steps when asking for a roll and checking prime numbers.
You should not rely on the previous history on prime results.
""",
tools=[
roll_die,
],
)
Could you please retry with our latest release? If the issue still happens, could you please provide a minimal runnable example code to help us reproduce it?
Please feel free to reopen if the issue still exits!