langflow-ai/langflow · error · UserComponentError

code size {encoded_size} bytes exceeds limit of {MAX_COMPONE

Error message

code size {encoded_size} bytes exceeds limit of {MAX_COMPONENT_SOURCE_BYTES} bytes

What it means

Raised when the UTF-8 encoded component source exceeds MAX_COMPONENT_SOURCE_BYTES (1 MiB). Real generated components are far under 1 MB; the cap exists to catch runaway model outputs (repetition loops) and abuse. The size is measured on the encoded bytes, not characters.

Source

Thrown at src/backend/base/langflow/agentic/services/user_components.py:243

    if not _CLASS_NAME_RE.fullmatch(class_name):
        msg = (
            f"class_name must be a CamelCase identifier "
            f"(letters/digits/underscores, leading uppercase). Got: {class_name!r}"
        )
        raise UserComponentError(msg)
    if class_name.upper() in _WINDOWS_RESERVED_DEVICES:
        msg = f"class_name {class_name!r} is a Windows-reserved device name"
        raise UserComponentError(msg)


def _validate_code(code: str) -> None:
    if not code or not code.strip():
        msg = "code must be a non-empty string"
        raise UserComponentError(msg)
    encoded_size = len(code.encode("utf-8"))
    if encoded_size > MAX_COMPONENT_SOURCE_BYTES:
        msg = f"code size {encoded_size} bytes exceeds limit of {MAX_COMPONENT_SOURCE_BYTES} bytes"
        raise UserComponentError(msg)


def _resolve_components_dir(*, user_id: str | None) -> Path:
    """Resolve and create ``<sandbox>/.components/`` for the given user.

    Reuses the FS tool's authoritative sandbox resolver so the hash
    function, pepper handling, AUTO_LOGIN dispatch, and no-user refusal
    stay in one place. The reserved-segment guard does NOT apply here —
    this helper is the privileged writer that the guard is protecting.
    """
    component = FileSystemToolComponent()
    if user_id is not None:
        component._user_id = user_id  # noqa: SLF001 — privileged binding seam
    try:
        sandbox_root = component._validate_root()  # noqa: SLF001
    except PermissionError as exc:
        # PermissionError from _validate_root happens in two cases:
        # 1. AUTO_LOGIN=False and no user_id → translate to our domain error.

View on GitHub (pinned to 976ec789d2)

Solutions

  1. Move large embedded data out of the component and load it from file storage or a URL at runtime.
  2. If the code is a runaway model output, regenerate with a shorter max-length constraint.
  3. As a last resort raise MAX_COMPONENT_SOURCE_BYTES in your fork — but 1 MiB signals something wrong with the input.

Example fix

# before
code = 'class Big:\n    DATA = "' + base64.b64encode(huge_file).decode() + '"'
register_user_component(user_id=uid, class_name="Big", code=code)

# after
code = 'class Big:\n    def load(self):\n        return download_or_read_from_storage("big.bin")'
register_user_component(user_id=uid, class_name="Big", code=code)
Defensive patterns

Strategy: validation

Validate before calling

MAX_BYTES = 1 * 1024 * 1024

def code_within_limit(code: str) -> bool:
    return len(code.encode("utf-8")) <= MAX_BYTES

Try / catch

try:
    register_user_component(user_id=uid, class_name=name, code=code)
except UserComponentError as e:
    if "exceeds limit" in str(e):
        code = truncate_or_externalize(code)  # move data blobs out

Prevention

When it happens

Trigger: register_user_component with a code payload larger than 1048576 bytes — e.g. a model stuck in a repetition loop emitting megabytes of similar lines, or embedded base64 blobs/data URIs inside the component.

Common situations: LLM degenerate repetition during long streams; developers embedding large lookup tables or serialized model weights directly in component code instead of loading from storage.

Related errors


AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14). Data as JSON: /api/errors/4340768e10c7dfef. Report an issue: GitHub.