{"record":{"id":"04e7654a328f4a5b","repo":"virattt/ai-hedge-fund","slug":"unknown-model-m-name-r-in-strategy-strategy-nam","errorCode":null,"errorMessage":"unknown model {m.name!r} in strategy {strategy.name!r}; available: {sorted(ALPHA_MODEL_REGISTRY)}","messagePattern":"unknown model (.+?) in strategy (.+?); available: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"hedge_fund/fund/spec.py","lineNumber":205,"sourceCode":"    The `models` override (strategy name -> instances) exists for tests to\n    inject fakes; production callers let the registry build the staff.\n    \"\"\"\n\n    def __init__(\n        self,\n        spec: FundSpec,\n        models: dict[str, list[AlphaModel]] | None = None,\n    ) -> None:\n        self.spec = spec\n        self.strategies: list[tuple[StrategySpec, list[AlphaModel]]] = []\n        for strategy in spec.strategies:\n            if models is not None:\n                self.strategies.append((strategy, models[strategy.name]))\n                continue\n            staff = []\n            for m in strategy.models:\n                if m.name not in ALPHA_MODEL_REGISTRY:\n                    raise ValueError(\n                        f\"unknown model {m.name!r} in strategy \"\n                        f\"{strategy.name!r}; available: {sorted(ALPHA_MODEL_REGISTRY)}\"\n                    )\n                staff.append(ALPHA_MODEL_REGISTRY[m.name](**m.params))\n            self.strategies.append((strategy, staff))\n","sourceCodeStart":187,"sourceCodeEnd":211,"githubUrl":"https://github.com/virattt/ai-hedge-fund/blob/eff8a7320fcf0b473b135690fa1a5b0d9b022a83/hedge_fund/fund/spec.py#L187-L211","documentation":"Raised in Fund.__init__ (hedge_fund/fund/spec.py:205) when a strategy's model list references a name that is not in ALPHA_MODEL_REGISTRY. The registry maps model names to AlphaModel classes; the error message lists the available names so the fix is immediate. This validates that the mandate's model names match the code's registry — a config/code drift guard.","triggerScenarios":"Constructing Fund(spec) where a StrategySpec.models entry has name='value_hunter' but the registry only knows e.g. 'value', 'momentum'. Happens after: renaming an alpha model in code without updating mandates; loading a mandate written for a newer/older build; a typo in the YAML model name. Only fires when models=None (the normal path) — passing a prebuilt models dict bypasses registry lookup via models[strategy.name].","commonSituations":"Upgrading the library after an alpha model was renamed/removed; hand-editing a mandate YAML and misspelling a model; sharing mandates between machines running different versions of the code.","solutions":["Read the error message: it prints sorted(ALPHA_MODEL_REGISTRY) — replace the bad name in the mandate YAML with one of those.","If the name should exist, check for a version mismatch: the mandate was written against a different build — update the mandate or pin/use the build that has that model.","If you legitimately added a new model, register it in ALPHA_MODEL_REGISTRY before referencing it in a spec."],"exampleFix":"# before (mandate.yaml)\nstrategies:\n  - name: core\n    models:\n      - name: warren_buffet   # typo -> ValueError: unknown model 'warren_buffet'\n\n# after\nstrategies:\n  - name: core\n    models:\n      - name: warren_buffett  # exact registry key","handlingStrategy":"validation","validationCode":"from hedge_fund.signals import ALPHA_MODEL_REGISTRY  # import path per build\n\ndef validate_models(spec) -> list[str]:\n    \"\"\"Names in the mandate that the current build cannot instantiate.\"\"\"\n    return sorted(\n        m.name\n        for s in spec.strategies\n        for m in s.models\n        if m.name not in ALPHA_MODEL_REGISTRY\n    )","typeGuard":"from hedge_fund.signals import ALPHA_MODEL_REGISTRY\n\ndef model_is_registered(name: str) -> bool:\n    return isinstance(name, str) and name in ALPHA_MODEL_REGISTRY","tryCatchPattern":"try:\n    fund = Fund(spec)\nexcept ValueError as e:\n    if \"unknown model\" in str(e):\n        raise SystemExit(f\"mandate references a model this build lacks: {e}\") from e\n    raise","preventionTips":["Validate mandate model names against ALPHA_MODEL_REGISTRY right after load_spec — the error message lists valid names, but failing early with the YAML path is friendlier.","Pin the library version that a mandate was authored against, or re-validate all mandates in CI after upgrades.","When renaming an alpha model in code, grep the mandate YAMLs in the same commit."],"tags":["config","registry","validation","model-name"],"backgroundTag":null,"analyzedSha":"eff8a7320fcf0b473b135690fa1a5b0d9b022a83","analyzedAt":"2026-08-15T00:22:46.567Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}