{"record":{"id":"b0e5bb3c78cb3f25","repo":"Comfy-Org/ComfyUI","slug":"positive-prompt-is-too-long-len-prompt-charact","errorCode":null,"errorMessage":"Positive prompt is too long: {len(prompt)} characters","messagePattern":"Positive prompt is too long: (.+?) characters","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_kling.py","lineNumber":286,"sourceCode":"    )\n\n\ndef is_valid_image_response(response: KlingImageGenerationsResponse) -> bool:\n    \"\"\"Verifies that the response contains a task result with at least one image.\"\"\"\n    return (\n        response.data is not None\n        and response.data.task_result is not None\n        and response.data.task_result.images is not None\n        and len(response.data.task_result.images) > 0\n    )\n\n\ndef validate_prompts(prompt: str, negative_prompt: str, max_length: int) -> bool:\n    \"\"\"Verifies that the positive prompt is not empty and that neither promt is too long.\"\"\"\n    if not prompt:\n        raise ValueError(\"Positive prompt is empty\")\n    if len(prompt) > max_length:\n        raise ValueError(f\"Positive prompt is too long: {len(prompt)} characters\")\n    if negative_prompt and len(negative_prompt) > max_length:\n        raise ValueError(\n            f\"Negative prompt is too long: {len(negative_prompt)} characters\"\n        )\n    return True\n\n\ndef validate_task_creation_response(response) -> None:\n    \"\"\"Validates that the Kling task creation request was successful.\"\"\"\n    if not is_valid_task_creation_response(response):\n        error_msg = f\"Kling initial request failed. Code: {response.code}, Message: {response.message}, Data: {response.data}\"\n        logging.error(error_msg)\n        raise Exception(error_msg)\n\n\ndef validate_video_result_response(response) -> None:\n    \"\"\"Validates that the Kling task result contains a video.\"\"\"\n    if not is_valid_video_response(response):","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_kling.py#L268-L304","documentation":"Raised by validate_prompts when the positive prompt exceeds the model's max_length (typically 2500 chars for Kling models, lower for some). Client-side length check performed before the API call so Kling never sees an oversized prompt.","triggerScenarios":"Feeding a Kling node a prompt longer than the max_length passed to validate_prompts — e.g. pasting an entire story, concatenating many prompt fragments, or LLM-generated mega-prompts.","commonSituations":"Chained prompt-template nodes accumulating text; copying long descriptions from documents; different Kling models having different limits (check the node's limit).","solutions":["Shorten the prompt below the model's character limit (2500 for most Kling video nodes)","Move overflow detail into the negative prompt only if that field has room — no, trim both to fit","If long context is needed, summarize the prompt with an LLM node before the Kling node","Show the character count in the UI/node to catch oversize prompts before running"],"exampleFix":"// before\nprompt = full_story_text  # 4800 chars\n\n// after\nMAX = 2500\nprompt = full_story_text[:MAX] if len(full_story_text) > MAX else full_story_text  # or summarize","handlingStrategy":"validation","validationCode":"MAX_PROMPT = 2500\n\ndef fits(prompt: str) -> bool:\n    return len(prompt) <= MAX_PROMPT\n\nassert fits(prompt), f\"prompt is {len(prompt)} chars, max {MAX_PROMPT}\"","typeGuard":"def prompt_within_limit(prompt: str, max_length: int = 2500) -> bool:\n    return isinstance(prompt, str) and 0 < len(prompt) <= max_length","tryCatchPattern":"try:\n    out = await kling_node(prompt=prompt, ...)\nexcept ValueError as e:\n    if \"too long\" in str(e):\n        out = await kling_node(prompt=prompt[:2500], ...)\n    else:\n        raise","preventionTips":["Trim or summarize long prompts before the Kling node","Surface character counts in prompt-building UIs","Remember each Kling model/node may pass a different max_length — check the node"],"tags":["kling","validation","prompt-length","pre-flight"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}