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

Pydantic basemodel with enum field not supported with_structured_output #9

Open
gopinathan-av opened this issue Apr 9, 2024 · 3 comments

Comments

@gopinathan-av
Copy link

llm.with_structured_output method does not support Pydantic models with enum fields. Getting following error.

    return master_prompts | self.get_default_model().with_structured_output(MessageRouter)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path>.venv/lib/python3.11/site-packages/langchain_core/_api/beta_decorator.py", line 109, in warning_emitting_wrapper
    return wrapped(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path>.venv/lib/python3.11/site-packages/langchain_cohere/chat_models.py", line 210, in with_structured_output
    llm = self.bind_tools([schema], **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path>.venv/lib/python3.11/site-packages/langchain_cohere/chat_models.py", line 189, in bind_tools
    formatted_tools = _format_to_cohere_tools(tools)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path>.venv/lib/python3.11/site-packages/langchain_cohere/cohere_agent.py", line 61, in _format_to_cohere_tools
    return [_convert_to_cohere_tool(tool) for tool in tools]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path>.venv/lib/python3.11/site-packages/langchain_cohere/cohere_agent.py", line 61, in <listcomp>
    return [_convert_to_cohere_tool(tool) for tool in tools]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path>.venv/lib/python3.11/site-packages/langchain_cohere/cohere_agent.py", line 155, in _convert_to_cohere_tool
    parameter_definitions={
                          ^
  File "<path>.venv/lib/python3.11/site-packages/langchain_cohere/cohere_agent.py", line 156, in <dictcomp>
    param_name: ToolParameterDefinitionsValue(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path>.venv/lib/python3.11/site-packages/pydantic/v1/main.py", line 341, in __init__
    raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for ToolParameterDefinitionsValue
type
  none is not an allowed value (type=type_error.none.not_allowed)
@harry-cohere
Copy link
Collaborator

Thanks for creating an issue @gopinathan-av - we'll aim to make a fix next week

@harry-cohere
Copy link
Collaborator

Sorry that it's taking a bit longer than thought to address this @gopinathan-av - aiming to have a better version this week. Thanks for your patience!

@RichmondAlake
Copy link

Hi @harry-cohere,

Following up on this issue, is there a fix for this?

Thanks

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

No branches or pull requests

3 participants