{"record":{"id":"992686d66f5211bb","repo":"FoundationAgents/MetaGPT","slug":"error-loading-configuration-for-model-model","errorCode":null,"errorMessage":"Error loading configuration for model '{model}': {str(e)}","messagePattern":"Error loading configuration for model '(.+?)': (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/ext/spo/utils/llm_client.py","lineNumber":51,"sourceCode":"            raise ValueError(\"'model' parameter is required\")\n\n        try:\n            model_config = ModelsConfig.default().get(model)\n            if model_config is None:\n                raise ValueError(f\"Model '{model}' not found in configuration\")\n\n            config = model_config.model_copy()\n\n            for key, value in kwargs.items():\n                if hasattr(config, key):\n                    setattr(config, key, value)\n\n            return config\n\n        except AttributeError:\n            raise ValueError(f\"Model '{model}' not found in configuration\")\n        except Exception as e:\n            raise ValueError(f\"Error loading configuration for model '{model}': {str(e)}\")\n\n    async def responser(self, request_type: RequestType, messages: List[dict]) -> str:\n        llm_mapping = {\n            RequestType.OPTIMIZE: self.optimize_llm,\n            RequestType.EVALUATE: self.evaluate_llm,\n            RequestType.EXECUTE: self.execute_llm,\n        }\n\n        llm = llm_mapping.get(request_type)\n        if not llm:\n            raise ValueError(f\"Invalid request type. Valid types: {', '.join([t.value for t in RequestType])}\")\n\n        response = await llm.acompletion(messages)\n        return response.choices[0].message.content\n\n    @classmethod\n    def initialize(cls, optimize_kwargs: dict, evaluate_kwargs: dict, execute_kwargs: dict) -> None:\n        \"\"\"Initialize the global instance\"\"\"","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/ext/spo/utils/llm_client.py#L33-L69","documentation":"A catch-all wrapper thrown by SPO_LLM._load_llm_config: any exception other than AttributeError raised while looking up or copying the model configuration is re-raised as ValueError with the original message appended. The inner exception string is the real diagnostic; common inner causes are malformed models yaml, missing required config fields, or model_copy failing on an incomplete config object.","triggerScenarios":"ModelsConfig.default().get(model) raises a non-AttributeError error (e.g. yaml parse error inside the config loader, pydantic validation error in model_copy, missing required api field); or setattr on the copied config triggers pydantic validation failure for one of the kwargs values.","commonSituations":"Malformed models.yaml (tabs, bad indentation, duplicate keys); a model entry missing mandatory fields so pydantic rejects it during copy; passing kwargs with wrong types (e.g. temperature as string); version upgrade changing the ModelsConfig schema so old yaml entries fail validation.","solutions":["Read the embedded '{str(e)}' portion — it carries the underlying exception; fix that root cause first.","Validate the models yaml loads cleanly: yaml.safe_load it in a REPL before running SPO.","Check that every model entry contains all required fields for the current MetaGPT version's config schema.","Ensure kwargs passed to initialize contain only valid, correctly-typed fields for the model config."],"exampleFix":"// before\n# models.yaml entry missing api_key causes inner validation error\nmy-model:\n  api_type: openai\n\n// after\nmy-model:\n  api_type: openai\n  base_url: https://api.openai.com/v1\n  api_key: YOUR_KEY\n  timeout: 600","handlingStrategy":"try-catch","validationCode":"import yaml\nfrom pathlib import Path\n\ndef yaml_ok(p: Path) -> bool:\n    try:\n        yaml.safe_load(p.read_text(encoding=\"utf-8\"))\n        return True\n    except yaml.YAMLError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    SPO_LLM.initialize(opt, eva, exe)\nexcept ValueError as e:\n    if str(e).startswith(\"Error loading configuration\"):\n        logger.error(\"SPO model config failed: %s\", e)  # inner cause is embedded\n        raise\n    raise","preventionTips":["Validate models.yaml with a lint step in CI (yaml.safe_load + schema check).","Never pass untyped kwargs to initialize; keep a typed dataclass for model kwargs."],"tags":["configuration","spo","llm","wrapper-exception"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}