HKUDS/Vibe-Trading · error · ValueError
{field_name} is required and cannot be empty
Error message
{field_name} is required and cannot be empty What it means
normalize_currency rejects currency codes that are empty after stripping — the field is mandatory and has no default. Raised from model __post_init__ and get_rate.
Source
Thrown at agent/src/entities/models.py:89
Codes are upper-cased and stripped. Length is deliberately not constrained
to three characters: this project also handles crypto quote assets such as
``USDT``, and rejecting them would push callers into faking a code.
Args:
value: Raw currency code, e.g. ``" usd "``.
field_name: Name used in the error message, for caller context.
Returns:
The canonical code, e.g. ``"USD"``.
Raises:
ValueError: If the code is empty, not a string, or contains whitespace.
"""
if not isinstance(value, str):
raise ValueError(f"{field_name} must be a string, got {type(value).__name__}")
cleaned = value.strip().upper()
if not cleaned:
raise ValueError(f"{field_name} is required and cannot be empty")
if any(ch.isspace() for ch in cleaned):
raise ValueError(f"{field_name} cannot contain whitespace, got {value!r}")
return cleaned
def normalize_date(value: date | datetime | str, *, field_name: str = "date") -> date:
"""Coerce a supported date input to a plain ``datetime.date``.
``datetime`` instances are truncated to their date, because a cash flow
settles on a day, not at a timestamp; keeping the time component would make
two flows on the same day compare unequal for no economic reason.
Strings must be ISO-8601 (``YYYY-MM-DD``, optionally with a time part).
Ambiguous regional formats such as ``03/04/2024`` are rejected rather than
guessed, since guessing day-first vs month-first is a silent wrong answer.
Args:
value: A ``date``, a ``datetime``, or an ISO-8601 string.View on GitHub (pinned to 80ffdda44c)
Solutions
- Supply a real ISO code like 'USD'
- Skip/repair rows with blank currency before constructing models
- Add form/API-level required-field validation
Example fix
# before EntityRate(currency=row['ccy'].strip(), ...) # after EntityRate(currency=row['ccy'].strip() or 'USD', ...)
Defensive patterns
Strategy: validation
Validate before calling
ccy = (raw or '').strip().upper() if not ccy: ccy = 'USD' # or reject row
Try / catch
except ValueError as e:
if 'cannot be empty' in str(e): default or skip the record Prevention
- Treat currency as required in ingestion schemas
When it happens
Trigger: Passing currency='' or currency=' ' to an entities model constructor or get_rate.
Common situations: Blank cells in CSVs feeding model constructors, or empty form fields propagated into the API.
Understand the failure class
Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.
Related errors
- {field_name} must be a string, got {type(value).__name__}
- {field_name} cannot contain whitespace, got {value!r}
- entity_id is required and cannot be empty
- kind is required and cannot be empty
- pre_translated=True asserts the flows were already converted
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/c6abbf586e8460a0.
Report an issue: GitHub.