{"record":{"id":"38480f99e132b422","repo":"calesthio/OpenMontage","slug":"prompt-exceeds-kling-image-generation-limit-of-250","errorCode":null,"errorMessage":"prompt exceeds Kling image generation limit of 2500 characters","messagePattern":"prompt exceeds Kling image generation limit of 2500 characters","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/graphics/kling_official_image.py","lineNumber":268,"sourceCode":"            api_family = \"omni\"\n        if api_family == \"omni\":\n            return self._build_omni_request(inputs)\n        return self._build_generation_request(inputs)\n\n    def _build_generation_request(self, inputs: dict[str, Any]) -> dict[str, Any]:\n        prompt = self._prompt(inputs)\n        model_name = str(inputs.get(\"model_name\") or \"kling-v3\")\n        if model_name not in IMAGE_GENERATION_MODELS:\n            raise ValueError(f\"model_name {model_name!r} is not supported for api_family=generation\")\n        payload: dict[str, Any] = {\n            \"model_name\": model_name,\n            \"prompt\": prompt,\n            \"resolution\": inputs.get(\"resolution\", \"1k\"),\n            \"n\": int(inputs.get(\"n\", 1) or 1),\n            \"aspect_ratio\": inputs.get(\"aspect_ratio\", \"16:9\"),\n        }\n        if len(prompt) > 2500:\n            raise ValueError(\"prompt exceeds Kling image generation limit of 2500 characters\")\n        if inputs.get(\"negative_prompt\"):\n            payload[\"negative_prompt\"] = inputs[\"negative_prompt\"]\n        image = normalize_image_input(inputs.get(\"image_url\"), inputs.get(\"image_path\"))\n        if image:\n            payload[\"image\"] = image\n        if inputs.get(\"image_reference\"):\n            payload[\"image_reference\"] = inputs[\"image_reference\"]\n        for key in (\"image_fidelity\", \"human_fidelity\"):\n            if inputs.get(key) is not None:\n                payload[key] = inputs[key]\n        elements = normalize_element_list(inputs.get(\"element_list\"))\n        if elements:\n            payload[\"element_list\"] = elements\n        self._copy_common_task_fields(inputs, payload)\n        return {\n            \"protocol\": \"classic\",\n            \"path\": \"/v1/images/generations\",\n            \"payload\": payload,","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/graphics/kling_official_image.py#L250-L286","documentation":"ValueError raised when the prompt for a Kling image generation request exceeds 2500 characters, the documented API limit. The check runs client-side during request building, before any network call, so no quota is consumed.","triggerScenarios":"Passing a very long prompt (elaborate scene descriptions, pasted context, or an agent concatenating instructions) to the generation API family; prompts padded with references or negative instructions.","commonSituations":"LLM agents generating unbounded prompt text; concatenating prompt + style descriptors + camera notes into one string; localizing to character-heavy languages where 2500 chars arrive quickly.","solutions":["Trim the prompt to under 2500 characters; move secondary detail into negative_prompt (subject to its own limits)","Compress verbose descriptions to the essential subject, style, and composition cues","If using an agent, add a truncation/summarization step before the tool call","Compute len(prompt) before invoking the tool to fail fast in your own code"],"exampleFix":"// before\ninputs = {\"prompt\": very_long_description}  // 4000 chars\n// after\nprompt = very_long_description[:2490].rsplit(\" \", 1)[0]\ninputs = {\"prompt\": prompt}","handlingStrategy":"validation","validationCode":"assert len(prompt) <= 2500, f\"prompt is {len(prompt)} chars; Kling limit is 2500\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Truncate or summarize agent-generated prompts before dispatch","Move negative constraints to negative_prompt","Add prompt length to your pre-flight validation suite"],"tags":["kling","image-generation","prompt-limit","validation"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}