You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am encountering a ValidationError when using the structured_llm.invoke method to generate a list of analysts. The error indicates that the required fields affiliation and description are missing for each analyst in the Perspective model. Here's the relevant code snippet:
ValidationError: 6 validation errors for Perspective
analysts.0.affiliation
Field required [type=missing, input_value={'name': 'Dr. Anya Sharma...e': 'Lead AI Scientist'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.10/v/missing
analysts.0.description
Field required [type=missing, input_value={'name': 'Dr. Anya Sharma...e': 'Lead AI Scientist'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.10/v/missing
analysts.1.affiliation
Field required [type=missing, input_value={'role': 'Chief Software ...name': 'Mr. Ben Carter'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.10/v/missing
analysts.1.description
Field required [type=missing, input_value={'role': 'Chief Software ...name': 'Mr. Ben Carter'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.10/v/missing
analysts.2.affiliation
Field required [type=missing, input_value={'role': 'Senior Tech Pol...ame': 'Ms. Chloe Davis'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.10/v/missing
analysts.2.description
Field required [type=missing, input_value={'role': 'Senior Tech Pol...ame': 'Ms. Chloe Davis'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.10/v/missing
Expected Behavior:
The structured_llm.invoke method should return a valid Perspective object with all required fields (affiliation, name, role, and description) populated for each analyst.
Actual Behavior:
The method fails with a ValidationError because the affiliation and description fields are missing in the generated output.
Code Snippet:
class Analyst(BaseModel):
affiliation: str = Field(
description="Primary affiliation of the analyst.",
)
name: str = Field(
description="Name of the analyst."
)
role: str = Field(
description="Role of the analyst in the context of the topic.",
)
description: str = Field(
description="Description of the analyst focus, concerns, and motives.",
)
@property
def persona(self) -> str:
return f"Name: {self.name}\nRole: {self.role}\nAffiliation: {self.affiliation}\nDescription: {self.description}\n"
class Perspective(BaseModel):
analysts: List[Analyst] = Field(
description="Comprehensive list of analysts with their roles and affiliations.",
)
def create_analysts(state: GenerateAnalystsState):
"""Create analysts for a given topic"""
topic = state["topic"]
max_analysts = state["max_analysts"]
human_analyst_feedback = state.get("human_analyst_feedback", '')
structured_llm = llm.with_structured_output(Perspective)
system_message = analyst_instructions.format(
topic=topic,
human_analyst_feedback=human_analyst_feedback,
max_analysts=max_analysts,
)
human_msg = """Generate the set of analysts."""
analysts_response = structured_llm.invoke(
[SystemMessage(content=system_message)] + [HumanMessage(content=human_msg)]
)
return {
"analysts": analysts_response.analysts
}
The text was updated successfully, but these errors were encountered:
I am encountering a ValidationError when using the structured_llm.invoke method to generate a list of analysts. The error indicates that the required fields affiliation and description are missing for each analyst in the Perspective model. Here's the relevant code snippet:
Error Message:
Expected Behavior:
The structured_llm.invoke method should return a valid Perspective object with all required fields (affiliation, name, role, and description) populated for each analyst.
Actual Behavior:
The method fails with a ValidationError because the affiliation and description fields are missing in the generated output.
Code Snippet:
The text was updated successfully, but these errors were encountered: