1- from typing import Any , Tuple
1+ from typing import Any
22
33from pydantic import BaseModel , Field
44
@@ -53,19 +53,17 @@ def _validate_output(self, task_output: TaskOutput) -> LiteAgentOutput:
5353
5454 Guardrail:
5555 { self .description }
56-
56+
5757 Your task:
5858 - Confirm if the Task result complies with the guardrail.
5959 - If not, provide clear feedback explaining what is wrong (e.g., by how much it violates the rule, or what specific part fails).
6060 - Focus only on identifying issues — do not propose corrections.
6161 - If the Task result complies with the guardrail, saying that is valid
6262 """
6363
64- result = agent .kickoff (query , response_format = LLMGuardrailResult )
65-
66- return result
64+ return agent .kickoff (query , response_format = LLMGuardrailResult )
6765
68- def __call__ (self , task_output : TaskOutput ) -> Tuple [bool , Any ]:
66+ def __call__ (self , task_output : TaskOutput ) -> tuple [bool , Any ]:
6967 """Validates the output of a task based on specified criteria.
7068
7169 Args:
@@ -79,13 +77,11 @@ def __call__(self, task_output: TaskOutput) -> Tuple[bool, Any]:
7977
8078 try :
8179 result = self ._validate_output (task_output )
82- assert isinstance (
83- result .pydantic , LLMGuardrailResult
84- ), "The guardrail result is not a valid pydantic model"
80+ if not isinstance (result .pydantic , LLMGuardrailResult ):
81+ raise ValueError ("The guardrail result is not a valid pydantic model" )
8582
8683 if result .pydantic .valid :
8784 return True , task_output .raw
88- else :
89- return False , result .pydantic .feedback
85+ return False , result .pydantic .feedback
9086 except Exception as e :
91- return False , f"Error while validating the task output: { str ( e ) } "
87+ return False , f"Error while validating the task output: { e !s } "
0 commit comments