HKUDS/Vibe-Trading · error · ValueError

{field_name} must be a date, datetime, or ISO-8601 string, g

Error message

{field_name} must be a date, datetime, or ISO-8601 string, got {type(value).__name__}

What it means

normalize_date only accepts date, datetime, or str inputs; any other type (int, None, pandas.Timestamp subclass edge cases aside) raises ValueError naming the field and actual type.

Source

Thrown at agent/src/entities/models.py:135

        return value.date()
    if isinstance(value, date):
        return value
    if isinstance(value, str):
        text = value.strip()
        if not text:
            raise ValueError(f"{field_name} is required and cannot be empty")
        try:
            return date.fromisoformat(text)
        except ValueError:
            pass
        try:
            return datetime.fromisoformat(text).date()
        except ValueError as exc:
            raise ValueError(
                f"{field_name}={value!r} is not ISO-8601 (YYYY-MM-DD); pass an "
                "explicit date_format instead of relying on inference"
            ) from exc
    raise ValueError(
        f"{field_name} must be a date, datetime, or ISO-8601 string, "
        f"got {type(value).__name__}"
    )


@dataclass(frozen=True)
class Entity:
    """A legal entity that issues, manages, or faces an instrument.

    Attributes:
        entity_id: Stable identifier, e.g. an LEI, a CIK, or a local key.
        name: Human-readable legal name.
        entity_type: Role the entity plays; see ``EntityType``.
        domicile: Country or jurisdiction code, free-form and optional.
        parent_id: ``entity_id`` of the parent entity, when part of a group.
    """

    entity_id: str

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Convert to date first: pd.to_datetime(v).date()
  2. Guard None: skip or default the record when the field is missing
  3. Add a type check/validation layer at ingestion

Example fix

# before
EntityLevel(date=row['dt'], ...)
# after
from datetime import date
EntityLevel(date=date.fromtimestamp(row['dt']), ...)  # or convert appropriately
Defensive patterns

Strategy: type-guard

Validate before calling

from datetime import date, datetime
if not isinstance(d, (date, datetime, str)): d = convert(d)

Type guard

def is_date_like(v) -> bool: return isinstance(v, (date, datetime, str))

Try / catch

except ValueError as e:
    if 'must be a date' in str(e): convert value to datetime.date and retry

Prevention

When it happens

Trigger: Passing date=None, date=20240331 (int), or a numpy datetime64 to a model constructor or date-taking function.

Common situations: Untyped data from APIs/dicts where the date field is null, or serial dates from Excel feeds.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/18240deb82c4a855. Report an issue: GitHub.