Skip to content

enum is not supported in array for function_declarations in convert_to_genai_function_declarations #858

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

Open
taoxinyi opened this issue Apr 14, 2025 · 1 comment

Comments

@taoxinyi
Copy link

The following code output doesn't contain enum field in array items field, which is supported in gemini

from typing import List

from langchain_core.tools import tool
from langchain_core.utils.function_calling import convert_to_openai_tool
from langchain_google_genai._function_utils import convert_to_genai_function_declarations


class Color(Enum):
    RED="RED"
    GREEN="GREEN"
    YELLOW="YELLOW"


@tool
def describe_colors(colors:List[Color]) -> str:
   """ describe colors """
   return "\n".join(colors)
print(convert_to_openai_tool(describe_colors))
print(convert_to_genai_function_declarations([describe_colors]))

output:

{'type': 'function', 'function': {'name': 'describe_colors', 'description': 'describe colors', 'parameters': {'properties': {'colors': {'items': {'enum': ['RED', 'GREEN', 'YELLOW'], 'type': 'string'}, 'type': 'array'}}, 'required': ['colors'], 'type': 'object'}}}
function_declarations {
  name: "describe_colors"
  description: "describe colors"
  parameters {
    type_: OBJECT
    description: "describe colors "
    properties {
      key: "colors"
      value {
        type_: ARRAY
        items {
          type_: STRING
          description: "Color"
        }
      }
    }
    required: "colors"
  }
}

expected:
enum fields in items field

@rsinger86
Copy link

I'm running into the same problem

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

2 participants