HKUDS/Vibe-Trading · error · ValueError
unknown entity_type {self.entity_type!r}; expected one of: {
Error message
unknown entity_type {self.entity_type!r}; expected one of: {valid} What it means
Raised by Entity.__post_init__ when the entity_type string cannot be matched to a member of the EntityType enum. The constructor coerces entity_type via EntityType(self.entity_type), so any value outside the enum's allowed values (including wrong case, whitespace, or typos) fails. The message lists all valid values.
Source
Thrown at agent/src/entities/models.py:174
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*
defaults, because the base already declares defaulted fields.
Attributes:
instrument_id: Stable identifier, e.g. an ISIN, a ticker, or a local key.
currency: Required ISO-style currency code of this instrument's cash
flows. Normalized to uppercase.
name: Human-readable name.View on GitHub (pinned to 80ffdda44c)
Solutions
- Pass an exact EntityType member value, e.g. EntityType.COMPANY.value, or the enum member itself
- Normalize input before construction: entity_type.strip().lower() and map aliases to canonical enum values
- If loading legacy data, build an alias map and translate unknown labels, surfacing a per-row error report instead of failing hard
Example fix
// before Entity(entity_id='e1', entity_type='Company') # after Entity(entity_id='e1', entity_type=EntityType.COMPANY.value)
Defensive patterns
Strategy: validation
Validate before calling
from agent.src.entities.models import Entity, EntityType
valid = {m.value for m in EntityType}
raw = row['entity_type'].strip().lower()
if raw not in valid:
raise KeyError(f"unknown entity_type {raw!r}; valid: {sorted(valid)}") Type guard
from agent.src.entities.models import EntityType
def is_valid_entity_type(v: str) -> bool:
try:
EntityType(v)
return True
except ValueError:
return False Try / catch
try:
e = Entity(entity_id=iid, entity_type=raw)
except ValueError as exc:
if 'unknown entity_type' in str(exc):
log.warning('skipping row with bad entity_type: %r', raw)
continue
raise Prevention
- Resolve entity_type to an EntityType member at the edge of your system
- Keep an alias map for legacy/free-text labels
- Reject or quarantine rows failing enum validation instead of guessing
When it happens
Trigger: Constructing an Entity (or subclass) with entity_type='organisation', 'Trust', ' fund', or any string not exactly matching an EntityType member value. The enum lookup is exact, so case or whitespace differences reject values that were stripped for other fields but not for entity_type.
Common situations: Loading entities from CSV/JSON/user input where type labels are free text; renaming or adding enum members between versions while stale records still carry old labels; passing a display-case label ('Company') instead of the stored value ('company').
Related errors
- entity {self.entity_id!r} cannot be its own parent
- unknown security_type {self.security_type!r}; expected one o
- unknown structure {self.structure!r}; expected one of: {vali
- amount must be numeric, got {self.amount!r}
- instrument_id is required and cannot be empty
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/75d3e91ba44bf369.
Report an issue: GitHub.