Skip to content

Commit 1fbffa4

Browse files
fix: apply ruff linting fixes to tasks module
1 parent 7426969 commit 1fbffa4

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/crewai/tasks/hallucination_guardrail.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
HallucinationGuardrail: Placeholder guardrail that validates task outputs.
77
"""
88

9-
from typing import Any, Optional, Tuple
9+
from typing import Any
1010

1111
from crewai.llm import LLM
1212
from crewai.tasks.task_output import TaskOutput
@@ -48,7 +48,7 @@ def __init__(
4848
self,
4949
context: str,
5050
llm: LLM,
51-
threshold: Optional[float] = None,
51+
threshold: float | None = None,
5252
tool_response: str = "",
5353
):
5454
"""Initialize the HallucinationGuardrail placeholder.
@@ -75,7 +75,7 @@ def description(self) -> str:
7575
"""Generate a description of this guardrail for event logging."""
7676
return "HallucinationGuardrail (no-op)"
7777

78-
def __call__(self, task_output: TaskOutput) -> Tuple[bool, Any]:
78+
def __call__(self, task_output: TaskOutput) -> tuple[bool, Any]:
7979
"""Validate a task output against hallucination criteria.
8080
8181
In the open source, this method always returns that the output is valid.

src/crewai/tasks/llm_guardrail.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Tuple
1+
from typing import Any
22

33
from 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

Comments
 (0)