Sorry for late reply :
here one exemple of function to extract Json structure of output :
def validate_json_output2(result: str) -> Tuple[bool, Any]:
json_pattern = r"\{.*\}"
match = re.search(json_pattern, result.raw, re.DOTALL)
if match:
json_data = match.group()
print(json_data)
return (True, json_data)
else:
return (False, "Output must be JSoN format")
class WriteDescription(BaseModel):
Description: str = Field(description="la description détaillée du canapé")
@task
def DescriBot_task(self) -> Task:
return Task(
config=self.tasks_config['DescriBot_task'],
output_pydantic = WriteDescription,
guardrail = validate_json_output2
)
I had the same error which was fix by changing to “Tuple[bool, Any]”
You also need to change result by result.raw which is equal to the string output