HKUDS/Vibe-Trading · error · ValueError

invalid regime {self.regime!r}; expected one of {REGIMES}

Error message

invalid regime {self.regime!r}; expected one of {REGIMES}

What it means

StrategyDiscovery models.py __post_init__ validates that the `regime` field of the evidence row is one of the module-level REGIMES constants. Any other string (typo, renamed label, new regime not in the enum) raises ValueError at dataclass construction time.

Source

Thrown at agent/src/strategy_discovery/models.py:166

    cost_sensitive: bool = False
    evidence_quality: str = QUALITY_INSUFFICIENT
    warnings: tuple[str, ...] = ()
    #: ISO date string ("YYYY-MM-DD") of the last harness verification.
    last_verified: str = ""
    #: Pipeline stage that produced this row; one of ``EVIDENCE_STAGES``.
    #: Defaults to the weakest claim: a row that says nothing about how it was
    #: produced must not read as though a backtest stood behind it.
    evidence_stage: str = "hypothesis"
    #: Reproducible artifact reference: the backtest run directory whose
    #: ``artifacts/`` this row was computed from.
    provenance: str = ""
    #: JSON string naming the regime-labeling parameters (window, bear/bull
    #: thresholds, Sharpe annualization) used when this row was computed.
    regime_definition: str = ""

    def __post_init__(self) -> None:
        if self.regime not in REGIMES:
            raise ValueError(
                f"invalid regime {self.regime!r}; expected one of {REGIMES}"
            )
        if self.evidence_stage not in EVIDENCE_STAGES:
            raise ValueError(
                f"invalid evidence_stage {self.evidence_stage!r}; "
                f"expected one of {EVIDENCE_STAGES}"
            )
        if self.evidence_stage in STAGES_REQUIRING_PROVENANCE and not self.provenance:
            raise ValueError(
                f"evidence_stage {self.evidence_stage!r} claims a computed "
                f"result, so provenance must name the run it was computed "
                f"from; got an empty provenance for strategy "
                f"{self.strategy_id!r} / regime {self.regime!r}"
            )


@dataclass(frozen=True)
class StrategySummary:

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Check strategy_discovery.models.REGIMES and use one of those exact values
  2. If you introduced a new regime, add it to REGIMES in the same change
  3. If reading stored rows, regenerate/reload them with a matching pipeline version

Example fix

# before
row = Evidence(regime='neutral', ...)
# after
from agent.src.strategy_discovery.models import REGIMES
row = Evidence(regime='bear', ...)  # one of REGIMES
Defensive patterns

Strategy: validation

Validate before calling

from agent.src.strategy_discovery.models import REGIMES
if regime not in REGIMES:
    raise KeyError(f'unknown regime {regime!r}; known: {REGIMES}')

Type guard

def is_valid_regime(r: str) -> bool:
    from agent.src.strategy_discovery.models import REGIMES
    return r in REGIMES

Try / catch

try:
    row = Evidence(regime=regime, ...)
except ValueError as e:
    if 'invalid regime' in str(e): map/regenerate the row or skip it
    else: raise

Prevention

When it happens

Trigger: Constructing the evidence dataclass with regime='neutral' when REGIMES only contains e.g. 'bull'/'bear', or loading rows produced by an older/newer pipeline whose regime labels differ.

Common situations: Version mismatch between the process that wrote evidence rows and the reader; typos or case differences ('Bull' vs 'bull'); adding a new regime label without updating the REGIMES constant.

Related errors


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