Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#7652·crewAI

[BUG] Shared serializer turns Enum values into repr strings

Author: gaoanze888Created Sep 20, 2026Updated Sep 29, 2026

Description

crewai.utilities.serialization.to_serializable() has no Enum branch, so any plain Enum value falls through to the repr() fallback. A string-valued enum such as Status.OK = "ok" is serialized as "<Status.OK: 'ok'>" instead of "ok".

This is not cosmetic. The shared serializer backs Flow expression outputs (flow/runtime/_outputs.py) and trace event conversion (safe_serialize_to_dict()), so an enum emitted by a flow method or included in trace data loses its declared wire value. IntEnum values currently pass through the int branch and keep their value only by accident of inheritance.

Enum values used as dictionary keys are also unstable: _to_serializable_key() produces a string containing the object id(), for example key_4383468448_<Key.X: 'x'>, which changes between runs.

This report was prepared with AI assistance. I cannot apply repository labels as an external contributor; please add the required llm-generated label.

Steps to reproduce

python
from enum import Enum
from crewai.utilities.serialization import to_serializable

class Status(Enum):
    OK = "ok"

assert to_serializable({"status": Status.OK}) == {"status": "ok"}
# AssertionError: actual value is {"status": "<Status.OK: 'ok'>"}

Expected behavior

Enums should serialize to their declared .value consistently, for both values and dictionary keys. IntEnum, date-valued, and tuple-valued enums should recurse through the same value path so they keep their intended semantics.

Screenshots/Code snippets

The serializer handles primitives, UUIDs, dates, collections, dataclasses, and Pydantic models, then defaults everything else to repr(obj). Enum is missing between the primitive check and the fallback.

Operating System

macOS Sonoma

Python Version

3.13 (supported by the repository; not listed in the issue template)

crewAI Version

Current main (0374c631297f)

crewAI Tools Version

Current main (0374c631297f)

Virtual Environment

Venv (uv)

Evidence

A deterministic offline reproduction fails on current main and passes once Enum expands to to_serializable(obj.value) before the primitive check, with _to_serializable_key() doing the same for keys.

Possible Solution

Handle Enum first in to_serializable() by recursing into obj.value, and mirror that in _to_serializable_key().

Additional context

Closed, unmerged PR #5180 contained a similar enum-value fix inside a much broader tracing change; it was closed stale with maintainers inviting a focused follow-up. This issue scopes only the enum contract in the shared serializer.

Source: crewAIInc/crewAI

View original on GitHubView discussion on GitHub