Skip to content
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

[BUG] Nested pydantic structures do not work #657

Open
Shahar-Y opened this issue Dec 19, 2024 · 0 comments · May be fixed by #658
Open

[BUG] Nested pydantic structures do not work #657

Shahar-Y opened this issue Dec 19, 2024 · 0 comments · May be fixed by #658

Comments

@Shahar-Y
Copy link

Shahar-Y commented Dec 19, 2024

While working with gregpr07/browser-use, @MahlerTom and I tried to use Gemini 2.0 as seen in the example below.

import asyncio
from browser_use import Agent
from libs.genai.langchain_google_genai import ChatGoogleGenerativeAI


async def main():
    agent = Agent(
        task="Navigate to https://www.wikipedia.org/ and find the article about 'xAI (company)' and summarize it.",
        llm=ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp"),
    )
    result = await agent.run()
    print(result)

asyncio.run(main())

We experienced the following error in gemini :

 Unexpected error: Invalid argument provided to Gemini: 400 * GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[action].properties[input_text].properties: should be non-empty for OBJECT type
* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[action].properties[go_to_url].properties: should be non-empty for OBJECT type
* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[action].properties[scroll_up].properties: should be non-empty for OBJECT type
* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[action].properties[extract_content].properties: should be non-empty for OBJECT type
* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[action].properties[open_tab].properties: should be non-empty for OBJECT type
* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[action].properties[go_back].properties: should be non-empty for OBJECT type
* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[action].properties[search_google].properties: should be non-empty for OBJECT type
* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[action].properties[click_element].properties: should be non-empty for OBJECT type
* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[action].properties[done].properties: should be non-empty for OBJECT type  
* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[action].properties[switch_tab].properties: should be non-empty for OBJECT type
* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[action].properties[scroll_down].properties: should be non-empty for OBJECT type

Stacktrace:
Traceback (most recent call last):
  File "..\langchain-google\libs\genai\langchain_google_genai\chat_models.py", line 220, in _achat_with_retry
    return await generation_method(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..\langchain-google\.venv\Lib\site-packages\google\ai\generativelanguage_v1beta\services\generative_service\async_client.py", line 406, in generate_content
    response = await rpc(
               ^^^^^^^^^^
  File "..\langchain-google\.venv\Lib\site-packages\google\api_core\retry\retry_unary_async.py", line 230, in retry_wrapped_func
    return await retry_target(
           ^^^^^^^^^^^^^^^^^^^
  File "..\langchain-google\.venv\Lib\site-packages\google\api_core\retry\retry_unary_async.py", line 160, in retry_target
    _retry_error_helper(
  File "..\langchain-google\.venv\Lib\site-packages\google\api_core\retry\retry_base.py", line 212, in _retry_error_helper
    raise final_exc from source_exc
  File "..\langchain-google\.venv\Lib\site-packages\google\api_core\retry\retry_unary_async.py", line 155, in retry_target
    return await target()
           ^^^^^^^^^^^^^^
  File "..\langchain-google\.venv\Lib\site-packages\google\api_core\grpc_helpers_async.py", line 88, in __await__
    raise exceptions.from_grpc_error(rpc_error) from rpc_error

This happens since gregpr07/browser-use use nested Pydantic structure, and after debugging the problem is in how langchain handles nested Pydantic structured in with_structured_output. Specifically, the issues occurred in _get_properties_from_schema method in libs\genai\langchain_google_genai\_function_utils.py.

@Shahar-Y Shahar-Y changed the title [BUG] Structured Output doesn't work with advanced schema [BUG] Nested pydantic structures do not work Dec 19, 2024
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 a pull request may close this issue.

1 participant