Comfy-Org/ComfyUI · error · Exception

Field ' cannot be longer than characters; was characters…

Error message

 Field '{field_name} cannot be longer than {max_length} characters; was {len(string)} characters long.

What it means

Raised by validate_string() in comfy_api_nodes/util/validation_utils.py when the string exceeds the node's max_length (checked after whitespace stripping). Providers cap prompt sizes (Heygen 1000/5000, Recraft 1000, Kling 2500, LTX 10000, Meshy 600...), and this guard fails locally instead of after upload. Note the message has cosmetic bugs — a leading space and a missing closing quote after the field name — but it fires correctly.

Solutions

  1. Shorten the prompt below the node's documented limit (see the node tooltip or provider API docs).
  2. If you need long context, switch to a provider node with a larger cap (e.g. text/LLM nodes) or summarize first with a local LLM node.
  3. Strip ComfyUI-specific syntax (weights, LoRA tags) that the target API ignores and that inflate length.
  4. When concatenating template segments, count characters before the API node and truncate deterministically.

Example fix

# before
validate_string(long_script, field_name='prompt', min_length=1, max_length=1000)
# Exception when len(long_script) > 1000

# after
validate_string(long_script[:1000], field_name='prompt', min_length=1, max_length=1000)
Defensive patterns

Strategy: validation

Validate before calling

MAX = 1000  # per node/provider
if len(text) > MAX:
    text = text[:MAX]

Try / catch

try: validate_string(prompt, max_length=MAX) except Exception as e: raise UserVisibleError(str(e)) from e

Prevention

When it happens

Trigger: Passing a long prompt to any node calling validate_string(prompt, max_length=N): a 1500-char prompt into Recraft (max 1000), a 4000-char Heygen script into a 1000-char field, or a huge pasted document into a Kling text box (2500).

Common situations: Users paste whole scripts/articles as prompts; prompt-template chains concatenate context until the string overruns; or a workflow tuned for one provider (LTX 10000) is reused with a stricter one (Meshy 600). Also triggered by LoRA-style prompt dumps including weighting syntax that the target API does not use anyway.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/3184bc85784b2b1a. Report an issue: GitHub.

Appendix: source

Thrown at comfy_api_nodes/util/validation_utils.py:190


def validate_string(
    string: str,
    strip_whitespace=True,
    field_name="prompt",
    min_length=None,
    max_length=None,
):
    if string is None:
        raise Exception(f"Field '{field_name}' cannot be empty.")
    if strip_whitespace:
        string = string.strip()
    if min_length and len(string) < min_length:
        raise Exception(
            f"Field '{field_name}' cannot be shorter than {min_length} characters; was {len(string)} characters long."
        )
    if max_length and len(string) > max_length:
        raise Exception(
            f" Field '{field_name} cannot be longer than {max_length} characters; was {len(string)} characters long."
        )


def validate_container_format_is_mp4(video: Input.Video) -> None:
    """Validates video container format is MP4."""
    container_format = video.get_container_format()
    if container_format not in ["mp4", "mov,mp4,m4a,3gp,3g2,mj2"]:
        raise ValueError(f"Only MP4 container format supported. Got: {container_format}")


def _ratio_from_tuple(r: tuple[float, float]) -> float:
    a, b = r
    if a <= 0 or b <= 0:
        raise ValueError(f"Ratios must be positive, got {a}:{b}.")
    return a / b

View on GitHub (pinned to 1c6d8d45b3)