HKUDS/Vibe-Trading · error · ValueError
entity_id is required and cannot be empty
Error message
entity_id is required and cannot be empty
What it means
The frozen entity dataclass's __post_init__ strips entity_id and rejects blank values — every entity must have a non-empty identifier.
Source
Thrown at agent/src/entities/models.py:167
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
name: str = ""
entity_type: EntityType = EntityType.ISSUER
domicile: str = ""
parent_id: str | None = None
def __post_init__(self) -> None:
"""Validate identifiers and coerce ``entity_type`` to its enum member.
Raises:
ValueError: If ``entity_id`` is blank or ``entity_type`` is unknown.
"""
cleaned = self.entity_id.strip() if isinstance(self.entity_id, str) else ""
if not cleaned:
raise ValueError("entity_id is required and cannot be empty")
object.__setattr__(self, "entity_id", cleaned)
object.__setattr__(self, "name", self.name.strip() if self.name else "")
try:
object.__setattr__(self, "entity_type", EntityType(self.entity_type))
except ValueError as exc:
valid = ", ".join(member.value for member in EntityType)
raise ValueError(
f"unknown entity_type {self.entity_type!r}; expected one of: {valid}"
) from exc
if self.parent_id is not None and self.parent_id == self.entity_id:
raise ValueError(f"entity {self.entity_id!r} cannot be its own parent")
@dataclass(frozen=True)
class Instrument:
"""Base class for anything that can be held and analysed.
Subclasses add asset-class specifics; they may only add fields *with*View on GitHub (pinned to 80ffdda44c)
Solutions
- Ensure the identifier field is populated before construction; skip blank-ID rows
- Validate the source column exists and rows aren't shifted (check delimiter/headers)
- Generate a fallback ID (e.g. slugified name) when the source lacks one
Example fix
# before Entity(entity_id=row['id'], name=row['name'], ...) # after if not (row['id'] or '').strip(): continue Entity(entity_id=row['id'], name=row['name'], ...)
Defensive patterns
Strategy: validation
Validate before calling
eid = (raw_id or '').strip() if not eid: eid = slugify(name) # or skip row
Type guard
def has_entity_id(v) -> bool: return isinstance(v, str) and bool(v.strip())
Try / catch
except ValueError as e:
if 'entity_id' in str(e): repair/skip the record Prevention
- Make ID columns required in source validation
- Generate stable fallback IDs from names
When it happens
Trigger: Constructing an entity model (Entity/EntityRate etc.) with entity_id='' or whitespace-only, or a non-str value that fails the strip guard.
Common situations: CSV rows with missing ID columns, None from JSON coerced via str(), or duplicate-header exports shifting columns.
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} is required and cannot be empty
- kind is required and cannot be empty
- {field_name} must be a string, got {type(value).__name__}
- {field_name} cannot contain whitespace, got {value!r}
- {field_name} must be a date, datetime, or ISO-8601 string, g
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/7458638e8ec3cc27.
Report an issue: GitHub.