{"record":{"id":"cb71797d9716563b","repo":"Comfy-Org/ComfyUI","slug":"negative-prompt-is-too-long-len-negative-prompt","errorCode":null,"errorMessage":"Negative prompt is too long: {len(negative_prompt)} characters","messagePattern":"Negative prompt is too long: (.+?) characters","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_kling.py","lineNumber":288,"sourceCode":"\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):\n        error_msg = f\"Kling task {response.data.task_id} succeeded but no video data found in response.\"\n        logging.error(\"Error: %s.\\nResponse: %s\", error_msg, response)","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_kling.py#L270-L306","documentation":"Raised by validate_prompts when the negative prompt is non-empty and exceeds max_length. Unlike the positive prompt, an empty negative is fine; only an over-long non-empty one fails. Client-side check, no network involved.","triggerScenarios":"Passing a negative prompt longer than the model limit — commonly a huge blocklist of terms accumulated from shared workflows or prompt presets.","commonSituations":"Copy-pasted 'universal negative prompt' lists from prompt-sharing sites that exceed the limit; merging multiple negative prompt outputs.","solutions":["Trim the negative prompt to the model's character limit","Deduplicate and remove redundant terms from the negative blocklist","Leave the negative prompt empty if the model (e.g. newer Kling models) largely ignores it"],"exampleFix":"// before\nnegative_prompt = giant_blocklist  # 3000 chars\n\n// after\nnegative_prompt = giant_blocklist[:2500]","handlingStrategy":"validation","validationCode":"MAX_PROMPT = 2500\n\nif negative_prompt:\n    negative_prompt = negative_prompt[:MAX_PROMPT]","typeGuard":"def negative_prompt_ok(neg: str | None, max_length: int = 2500) -> bool:\n    return not neg or len(neg) <= max_length","tryCatchPattern":"try:\n    out = await kling_node(prompt=prompt, negative_prompt=neg, ...)\nexcept ValueError as e:\n    if \"Negative prompt is too long\" in str(e):\n        out = await kling_node(prompt=prompt, negative_prompt=neg[:2500], ...)\n    else:\n        raise","preventionTips":["Deduplicate blocklist-style negative prompts","Cap the negative prompt at the same limit as the positive one when composing workflows"],"tags":["kling","validation","negative-prompt","pre-flight"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}