Open srtab opened 3 days ago
After digging a bit on the code, it seams the error is not specifically related with ChatAnthropic
but with BaseChatModel
and method with_structured_output
.
The schema passed to the method is a Pydantic model, which means PydanticToolsParser
is used. Checking the parse_result
from PydanticToolsParser
, the name_dict = {tool.__name__: tool for tool in self.tools}
is built using the tool.__name__
as key. When the tools are bind, the method convert_to_openai_tool
is used to convert Pydantic model to a tool and that method uses title
generated by model_json_schema
and not __name__
, leading the a mismatch on the tool names.
My suggestion is change PydanticToolsParser
to build name_dict
using the result of convert_to_openai_tool(tool)["function"]["name"]
for each tool: name_dict = {convert_to_openai_tool(tool)["function"]["name"] tool for tool in self.tools}
.
If that's ok, i can open a pull request with a fix.
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
Description
When i use Pydantic models with
model_config = ConfigDict(title="request_assessment")
the exceptionKeyError: 'request_assessment'
is raised when i useChatAnthropic
. WithChatOpenAI
, no problems.System Info