-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tool calling with Gemini through Vertex AI fails because of argument with Union type #463
Comments
this is actually a limitation of the gemini api (you'll notice the error originates from googles sdk) and i'm not sure how much we can do about it on the langchain side. we could perhaps try to convert union arg types into multiple distinct args under the hood and then reassemble, but i worry that might be unintuitive from end user perspective / silently degrade model performance because schemas become more confusing. but for posterity here's what that idea could look like # lc automatically converts
class FailingTool(TypedDict):
arg1: Union[date, datetime]
# into
class FailingToolDerived(TypedDict):
arg1_date: NotRequired[date]
arg1_datetime: NotRequired[datetime]
# at runtime FailingToolDerived is passed to Gemini, and then output is parsed back into a FailingTool cc @lkuligin |
Yes that makes sense. |
we send a warning: "Key 'anyOf' is not supported in schema, ignoring". somestimes just ignoring still helps to produce valid responses (but I see your point, I'm not sure what's better: always failing or sending warnings that might be missed / ignored). Maybe we can make a warning a little bit more clear, wdyt? |
Faced a similar problem and a sorta hack around the same was to give each class an optional type with default value none |
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
Description
Hello!
I'm going through the Customer Support Chatbot tutorial using Gemini through Vertex AI instead of Anthropic and it crashes during Part 1 - Example Conversation.
When the graph calls the LLM, it doesn't accept the request because of an error with the provided tool list.
From what I can tell, the search_flight tool definition isn't handled well because of its arguments of type Optional[date | datetime], specifically the union [date | datetime]. It seems their type doesn't get included in the tool description that is passed to the model so the model rejects it.
I've replicated it with the provided example code.
System Info
System Information
Package Information
The text was updated successfully, but these errors were encountered: