HKUDS/Vibe-Trading · error · TypeError
{model}: generated_at must be a datetime.datetime supplied b
Error message
{model}: generated_at must be a datetime.datetime supplied by the caller, got {type(value).__name__}. This module never calls datetime.now() -- pass datetime.now(timezone.utc) yourself. What it means
_require_generated_at enforces that generated_at is a datetime.datetime explicitly supplied by the caller. The module deliberately never calls datetime.now() itself, so artifact timestamps are deterministic and reproducible; a non-datetime (string, date, float) is a TypeError.
Source
Thrown at agent/src/quantlib/valuation/artifact.py:352
def _require_generated_at(value: datetime, model: str) -> datetime:
"""Check that a caller-supplied timestamp is usable, and only that.
This function never reads a clock. Its only job is to reject a call that
did not supply one properly -- see the module docstring.
Args:
value: The candidate ``generated_at``.
model: Name of the calling builder, for the error message.
Returns:
``value`` unchanged.
Raises:
TypeError: If ``value`` is not a ``datetime.datetime``.
ValueError: If ``value`` is timezone-naive.
"""
if not isinstance(value, datetime):
raise TypeError(
f"{model}: generated_at must be a datetime.datetime supplied by the "
f"caller, got {type(value).__name__}. This module never calls "
"datetime.now() -- pass datetime.now(timezone.utc) yourself."
)
if value.tzinfo is None or value.utcoffset() is None:
raise ValueError(
f"{model}: generated_at must be timezone-aware (e.g. "
"datetime.now(timezone.utc)), got a naive datetime "
f"{value!r} -- an artifact's timestamp must be unambiguous."
)
return value
# ---------------------------------------------------------------------------
# Canonical normalization: numbers, then the recursive flatten/hash engine
# ---------------------------------------------------------------------------
View on GitHub (pinned to 80ffdda44c)
Solutions
- Pass datetime.now(timezone.utc) (or a fixed aware datetime for reproducibility).
- When parsing from text, use datetime.fromisoformat(value) and ensure tzinfo is set.
- Use datetime.datetime, not datetime.date.
Example fix
# before build_dcf_artifact(generated_at="2026-01-01", ...) # after from datetime import datetime, timezone build_dcf_artifact(generated_at=datetime.now(timezone.utc), ...)
Defensive patterns
Strategy: type-guard
Validate before calling
from datetime import datetime
if not isinstance(generated_at, datetime):
raise TypeError("generated_at must be a datetime.datetime") Type guard
from datetime import datetime
def is_datetime(value) -> bool:
return isinstance(value, datetime) Prevention
- Use datetime.now(timezone.utc) at call sites; never strings.
- When loading from JSON, parse timestamps with datetime.fromisoformat.
When it happens
Trigger: build_dcf_artifact(generated_at="2026-01-01", ...); passing a datetime.date instead of datetime.datetime; passing a Unix timestamp float or None.
Common situations: Loading timestamps from JSON/YAML as strings; refactoring code that used date objects; test fixtures written with plain dates.
Understand the failure class
Background: "Wrong argument type", "must be a string", "expected Array or Prism::Scope": TypeError and ArgumentError when a library receives a value of the wrong type — this error's family across 28 libraries.
Related errors
- build_dcf_artifact: result must be a DCFResult, got {type(re
- build_comps_artifact: result must be a CompsResult, got {typ
- build_three_statement_artifact: result must be a ThreeStatem
- amount must be numeric, got {self.amount!r}
- metadata must be a mapping, got {type(self.metadata).__name_
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/7ca8d0a7a843a095.
Report an issue: GitHub.