HKUDS/Vibe-Trading · error · ValueError

ModelArtifact.model_name must be one of {_MODEL_NAMES}, got

Error message

ModelArtifact.model_name must be one of {_MODEL_NAMES}, got {self.model_name!r}

What it means

ModelArtifact's frozen dataclass __post_init__ validates that model_name is one of the known _MODEL_NAMES (dcf, comps, three_statement). This keeps artifacts self-describing so diffing and export dispatch can rely on the field.

Source

Thrown at agent/src/quantlib/valuation/artifact.py:256

    schema_version: str
    generated_at: datetime
    input_hash: str
    inputs: Mapping[str, Any]
    outputs: Mapping[str, Any]
    assumptions: tuple[AssumptionRecord, ...]
    result: Any
    excluded: tuple[str, ...]
    warnings: tuple[str, ...]

    def __post_init__(self) -> None:
        """Check the artifact's own invariants.

        Raises:
            ValueError: If ``model_name`` is not one of :data:`_MODEL_NAMES`,
                or ``input_hash`` is not a 64-character hex sha256 digest.
        """
        if self.model_name not in _MODEL_NAMES:
            raise ValueError(
                f"ModelArtifact.model_name must be one of {_MODEL_NAMES}, "
                f"got {self.model_name!r}"
            )
        if len(self.input_hash) != 64 or any(
            c not in "0123456789abcdef" for c in self.input_hash
        ):
            raise ValueError(
                f"ModelArtifact.input_hash must be a 64-character sha256 hex "
                f"digest, got {self.input_hash!r}"
            )


@dataclass(frozen=True)
class FieldChange:
    """One field that differs between two artifacts' inputs or outputs.

    Attributes:
        path: The dotted/bracket path that changed.

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Use one of the exact names in _MODEL_NAMES: 'dcf', 'comps', 'three_statement'.
  2. Prefer the build_dcf_artifact / build_comps_artifact / build_three_statement_artifact factories, which set model_name for you.
  3. If adding a genuinely new model, extend _MODEL_NAMES and its dispatch sites.

Example fix

// before
ModelArtifact(model_name="DCF", ...)
// after
ModelArtifact(model_name="dcf", ...)  # or use build_dcf_artifact(...)
Defensive patterns

Strategy: type-guard

Validate before calling

from quantlib.valuation.artifact import _MODEL_NAMES
assert model_name in _MODEL_NAMES, f"unknown model_name {model_name!r}"

Type guard

def is_known_model_name(name: str) -> bool:
    from quantlib.valuation.artifact import _MODEL_NAMES
    return name in _MODEL_NAMES

Prevention

When it happens

Trigger: ModelArtifact(model_name='DCF', ...) with wrong casing; a typo like 'dcfs'; or introducing a new model type without registering its name in _MODEL_NAMES.

Common situations: Constructing artifacts manually instead of via build_*_artifact; renaming model identifiers during a refactor; copy-pasting artifact construction code.

Related errors


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