{"record":{"id":"5f5989d1a3694e1a","repo":"calesthio/OpenMontage","slug":"mode-must-be-one-of-join-avatar-modes","errorCode":null,"errorMessage":"mode must be one of: {', '.join(AVATAR_MODES)}","messagePattern":"mode must be one of: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/avatar/kling_avatar.py","lineNumber":235,"sourceCode":"                \"cost_estimate_basis\": \"Conservative estimate pending official account-usage reconciliation.\",\n                **self._account_usage_result(inputs, client),\n                **self._callback_result_data(inputs, task_id),\n                **probed,\n            },\n            artifacts=[str(path) for path in paths],\n            cost_usd=self.estimate_cost(inputs),\n            duration_seconds=round(time.time() - start, 2),\n            model=\"kling-official-avatar\",\n        )\n\n    def _build_request(self, inputs: dict[str, Any]) -> dict[str, Any]:\n        image = normalize_image_input(inputs.get(\"image_url\"), inputs.get(\"image_path\"))\n        if not image:\n            raise ValueError(\"Kling avatar requires image_url or image_path\")\n\n        mode = str(inputs.get(\"mode\") or \"std\")\n        if mode not in AVATAR_MODES:\n            raise ValueError(f\"mode must be one of: {', '.join(AVATAR_MODES)}\")\n\n        payload: dict[str, Any] = {\n            \"image\": image,\n            \"mode\": mode,\n        }\n        if inputs.get(\"prompt\"):\n            payload[\"prompt\"] = str(inputs[\"prompt\"])\n\n        audio_source = self._copy_audio_input(inputs, payload)\n        self._copy_common_task_fields(inputs, payload)\n        return {\n            \"protocol\": \"classic\",\n            \"path\": \"/v1/videos/avatar/image2video\",\n            \"payload\": payload,\n            \"operation\": \"image_to_avatar_video\",\n            \"model\": \"kling-official-avatar\",\n            \"avatar_source\": inputs.get(\"image_url\") or inputs.get(\"image_path\"),\n            \"audio_source\": audio_source,","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/avatar/kling_avatar.py#L217-L253","documentation":"ValueError from KlingAvatarTool._build_request when the mode input is not a member of AVATAR_MODES ('std' is the default; the set typically also includes 'pro'). The mode selects the Kling avatar model tier; anything else would be rejected by the API anyway, so the client fails fast with the allowed list spelled out in the message.","triggerScenarios":"Passing mode='hd', mode='professional', mode=1 (int), or any string outside AVATAR_MODES to kling_avatar.","commonSituations":"Copying mode values from a different Kling tool (video generation uses different mode semantics); mode names changed between API versions; passing an empty mode expecting auto-detection.","solutions":["Read the message — it lists the valid modes — and set mode to one of them (or omit it; 'std' is the default).","Normalize user-supplied mode strings (lowercase, trim) before passing to the tool.","Pin the mode against the AVATAR_MODES constant imported from the module rather than hardcoding."],"exampleFix":"// before\nresult = tool.run({\"image_path\": \"p.png\", \"mode\": \"HD\", ...})\n\n// after\nfrom tools.avatar.kling_avatar import AVATAR_MODES\nmode = str(inputs.get(\"mode\", \"std\")).lower()\nassert mode in AVATAR_MODES, f\"mode must be one of {AVATAR_MODES}\"\nresult = tool.run({\"image_path\": \"p.png\", \"mode\": mode, ...})","handlingStrategy":"validation","validationCode":"mode = str(inputs.get(\"mode\") or \"std\").strip().lower()\nif mode not in AVATAR_MODES:\n    raise ValueError(f\"mode must be one of: {', '.join(AVATAR_MODES)}\")","typeGuard":"def is_valid_avatar_mode(mode: str) -> bool:\n    return mode in AVATAR_MODES","tryCatchPattern":null,"preventionTips":["Import AVATAR_MODES from the tool module instead of hardcoding the enum","Normalize user input (trim, lowercase) before validation"],"tags":["kling","avatar","enum-validation","input-validation"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}