From 636584acf1796e9c2ca7d7d450eda4f037ac3952 Mon Sep 17 00:00:00 2001 From: lorenzejay Date: Wed, 15 Oct 2025 13:22:28 -0700 Subject: [PATCH] Refactor Task Class Guardrail Type Annotation - Updated the type annotation for the `guardrails` field in the Task class from `list` to `Sequence` to enhance type safety and compatibility with various sequence types. - This change improves type checking and aligns with best practices for handling callable functions and string descriptions in guardrail validation. This update contributes to the overall robustness and maintainability of the Task class. --- src/crewai/task.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crewai/task.py b/src/crewai/task.py index dc4159ca5..47f7f5de8 100644 --- a/src/crewai/task.py +++ b/src/crewai/task.py @@ -5,7 +5,7 @@ import logging import threading import uuid import warnings -from collections.abc import Callable +from collections.abc import Callable, Sequence from concurrent.futures import Future from copy import copy as shallow_copy from hashlib import md5 @@ -153,7 +153,7 @@ class Task(BaseModel): description="Function or string description of a guardrail to validate task output before proceeding to next task", ) guardrails: ( - list[Callable[[TaskOutput], tuple[bool, Any]] | str] + Sequence[Callable[[TaskOutput], tuple[bool, Any]] | str] | Callable[[TaskOutput], tuple[bool, Any]] | str | None