From a0e5d913648c6131a59722b3eb71298fbabe6fbe Mon Sep 17 00:00:00 2001 From: Greyson LaLonde Date: Thu, 21 May 2026 03:08:47 +0800 Subject: [PATCH] fix: reject classes and builtins in _dotted_path_to_instance for symmetry --- lib/crewai/src/crewai/types/callback.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/crewai/src/crewai/types/callback.py b/lib/crewai/src/crewai/types/callback.py index a0703c9b3..0f60883d1 100644 --- a/lib/crewai/src/crewai/types/callback.py +++ b/lib/crewai/src/crewai/types/callback.py @@ -186,7 +186,20 @@ def _dotted_path_to_instance(value: Any) -> Any: If *value* is already a non-string object it is returned as-is. """ - if value is None or not isinstance(value, str): + if value is None: + return value + if not isinstance(value, str): + if inspect.isclass(value): + raise ValueError( + f"Expected an instance or dotted path string, got class " + f"{getattr(value, '__module__', '')}." + f"{getattr(value, '__qualname__', getattr(value, '__name__', ''))}." + ) + if type(value).__module__ == "builtins": + raise ValueError( + f"Expected an instance of a user-defined class or dotted " + f"path string, got builtin value {value!r}." + ) return value if "." not in value: raise ValueError(