Hello, I’m trying to get structured outputs, but I’m having trouble.
Problem Description
I’m encountering a persistent validation error in my CrewAI implementation when processing agent outputs through Pydantic. The task requires an agent (“Glancy”) to analyze missing requirements and output a JSON object matching this model:
class requirements_model(BaseModel):
isComplete: str = Field(description="Boolean indicating requirement completeness")
requirements: str = Field(description="Analysis of missing requirements")
Observed Failure
The task consistently fails with this validation error:
ValidationError: 1 validation error for TaskOutput
json_dict
Input should be a valid dictionary [type=dict_type, input_value='{...}', input_type=str]
Key Details
- Agent Output: Appears as valid JSON string:
# Agent: Interpret Agent
## Final Answer:
I am an Interpret Agent. My precision and attention to detail are unmatched,
and my ability to understand and interpret complex information is unparalleled.
Based on the provided code and test results, I have determined that the final
answer should be in JSON format with two keys: "isComplete" and "requirements".
Here is the final answer:
{
"isComplete": "true",
"requirements": [
{
"name": "Gearbox_fsm_type",
"type": "enum",
"values": ["First", "Second", "Third", "Fourth"]
},
{
"name": "input",
"type": "struct",
"fields": ["In_speed", "In_Throttle"]
},
{
"name": "output",
"type": "struct",
"fields": ["Out_gear"]
},
{
"name": "internal",
"type": "struct",
"fields": ["fsm_var"]
}
]
}
I have thoroughly reviewed the provided code and test results to ensure that myfinal answer is accurate and complete. I am confident that this answer meets
all requirements and will be accepted.
- CrewAI Configuration:
#### TASKS .yaml
interpret_missing_requirements:
description: >
Your task is to draft a detailed report based on the missing requeriments you found in:
{missing_requirements}
Take into account the last generated code:
{generated_code}
If you do your BEST WORK, you'll earn a $10,000 commission!
expected_output: >
A JSON object with a 2 keys: isComplete and requirements.
agent: Glancy
#### CREW .py
@task
def interpret_missing_requirements(self) -> Task:
return Task(
config=self.tasks_config['interpret_missing_requirements'],
output_json=requirements_model,
)
What am I doing erroneously?
Thanks in advance!