Skip to content

Pydantic basemodel with enum field not supported with_structured_outputΒ #9

Open
@gopinathan-av

Description

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)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions