You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/venv/iconolist/lib/python3.12/site-packages/langchain/agents/openai_tools/base.py", line 94, in create_openai_tools_agent
tools=[convert_to_openai_tool(tool, strict=strict) for tool in tools]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/venv/iconolist/lib/python3.12/site-packages/langchain_core/utils/function_calling.py", line 441, in convert_to_openai_tool
oai_function = convert_to_openai_function(tool, strict=strict)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/venv/iconolist/lib/python3.12/site-packages/langchain_core/utils/function_calling.py", line 388, in convert_to_openai_function
oai_function = cast(dict, format_tool_to_openai_function(function))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/venv/iconolist/lib/python3.12/site-packages/langchain_core/_api/deprecation.py", line 179, in warning_emitting_wrapper
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/venv/iconolist/lib/python3.12/site-packages/langchain_core/utils/function_calling.py", line 292, in format_tool_to_openai_function
if tool.tool_call_schema and not is_simple_oai_tool:
^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/venv/iconolist/lib/python3.12/site-packages/langchain_core/tools/base.py", line 457, in tool_call_schema
return _create_subset_model(
^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/venv/iconolist/lib/python3.12/site-packages/langchain_core/utils/pydantic.py", line 326, in _create_subset_model
return _create_subset_model_v2(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/venv/iconolist/lib/python3.12/site-packages/langchain_core/utils/pydantic.py", line 270, in _create_subset_model_v2
field = model.model_fields[field_name] # type: ignore
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'data'
Description
Note: The following is written for NavigateBackTool (where I first discovered the problem) but is the same for ExtractTextTool and CurrentWebPageTool.
The final line of the code above fails with the error message given. It fails in some sense because the args_schema of the NavigateBackTool claims to support a field 'data' which it actually does not (briefly, the code seems to get a list of properties which can be queried and then query them and there's a mismatch here). My guess is that this is a version mismatch between v1 and v2 of pydantic but I could be wrong (I am not a pydantic expert). I believe this was introduced in PR [0].
Looking at navigate_back.py I can see that the import of BaseModel has changed e.g. from [1] to [2], where [1] was explicitly including the v1 version of BaseModel (albeit from langchain_core) and 2 pulls from pydantic.BaseModel.
Other tools e.g. ClickTool don't have this problem, because they override BaseModel to provide and explicit "Input" class. I have confirmed that creating such a class is a workaround for this issue. FWIW I think there's a strong argument that making this empty set of params explicit and not implicit is better anyway.
Apologies that this isn't the most complete explanation but I hope it's enough for someone in the know to understand what's going in detail much more quickly than it would take me to understand exactly why e.g. 'data' is listed as a field when not actually present :) I have found [3] to be a great place to set a breakpoint to understand this.
Checked other resources
Example Code
The following code, with an OpenAI key specified at the TODO
Error Message and Stack Trace (if applicable)
Description
Note: The following is written for NavigateBackTool (where I first discovered the problem) but is the same for ExtractTextTool and CurrentWebPageTool.
The final line of the code above fails with the error message given. It fails in some sense because the
args_schema
of theNavigateBackTool
claims to support a field 'data' which it actually does not (briefly, the code seems to get a list of properties which can be queried and then query them and there's a mismatch here). My guess is that this is a version mismatch between v1 and v2 of pydantic but I could be wrong (I am not a pydantic expert). I believe this was introduced in PR [0].Looking at
navigate_back.py
I can see that the import of BaseModel has changed e.g. from [1] to [2], where [1] was explicitly including the v1 version of BaseModel (albeit from langchain_core) and 2 pulls from pydantic.BaseModel.Other tools e.g. ClickTool don't have this problem, because they override BaseModel to provide and explicit "Input" class. I have confirmed that creating such a class is a workaround for this issue. FWIW I think there's a strong argument that making this empty set of params explicit and not implicit is better anyway.
Apologies that this isn't the most complete explanation but I hope it's enough for someone in the know to understand what's going in detail much more quickly than it would take me to understand exactly why e.g. 'data' is listed as a field when not actually present :) I have found [3] to be a great place to set a breakpoint to understand this.
[0] #26443
[1] https://api.python.langchain.com/en/latest/_modules/langchain_community/tools/playwright/navigate_back.html#NavigateBackTool
[2] https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/tools/playwright/navigate_back.py
[3] Property method
tool_call_schema
in VENV_PATH/lib/python3.12/site-packages/langchain_core/tools/base.pySystem Info
The text was updated successfully, but these errors were encountered: