I'm trying to use LangChain’s structured output feature with a Gemini model, however, whenever I try to run the chain, I get the error:
ValueError: unknown enum label "any"
Here’s the code I have used:
from pydantic import BaseModel, Field
model = ChatGoogleGenerativeAI(
model="gemini-2.0-flash",
temperature=0,
)
class Topic_lists(BaseModel):
topic_lists: list[str] = Field(
..., description="list of suggested topics",
min_length=5, max_length=5
)
structured_model = model.with_structured_output(Topic_lists)
system_message = SystemMessagePromptTemplate.from_template("You are a {system_role}")
frst_human_message = HumanMessagePromptTemplate.from_template(
"List 5 possible research topics. "
"Be creative. "
"Output only the topics separated by a comma ','"
)
first_prompt = ChatPromptTemplate.from_messages([system_message, frst_human_message])
chain_1 = (
{"system_role": lambda x: x["system_role"]}
| first_prompt
| structured_model
| {"topics": lambda x: x.content}
)
# Invoke the chain
topics = chain_1.invoke({"system_role": "student researcher"})
I was strictly following the Langchain documentation, and I have tried many ways to resolve this. I am thinking if it is a dependency version problem...