{"record":{"id":"4340768e10c7dfef","repo":"langflow-ai/langflow","slug":"code-size-encoded-size-bytes-exceeds-limit-of-m","errorCode":null,"errorMessage":"code size {encoded_size} bytes exceeds limit of {MAX_COMPONENT_SOURCE_BYTES} bytes","messagePattern":"code size (.+?) bytes exceeds limit of (.+?) bytes","errorType":"validation","errorClass":"UserComponentError","httpStatus":null,"severity":"error","filePath":"src/backend/base/langflow/agentic/services/user_components.py","lineNumber":243,"sourceCode":"    if not _CLASS_NAME_RE.fullmatch(class_name):\n        msg = (\n            f\"class_name must be a CamelCase identifier \"\n            f\"(letters/digits/underscores, leading uppercase). Got: {class_name!r}\"\n        )\n        raise UserComponentError(msg)\n    if class_name.upper() in _WINDOWS_RESERVED_DEVICES:\n        msg = f\"class_name {class_name!r} is a Windows-reserved device name\"\n        raise UserComponentError(msg)\n\n\ndef _validate_code(code: str) -> None:\n    if not code or not code.strip():\n        msg = \"code must be a non-empty string\"\n        raise UserComponentError(msg)\n    encoded_size = len(code.encode(\"utf-8\"))\n    if encoded_size > MAX_COMPONENT_SOURCE_BYTES:\n        msg = f\"code size {encoded_size} bytes exceeds limit of {MAX_COMPONENT_SOURCE_BYTES} bytes\"\n        raise UserComponentError(msg)\n\n\ndef _resolve_components_dir(*, user_id: str | None) -> Path:\n    \"\"\"Resolve and create ``<sandbox>/.components/`` for the given user.\n\n    Reuses the FS tool's authoritative sandbox resolver so the hash\n    function, pepper handling, AUTO_LOGIN dispatch, and no-user refusal\n    stay in one place. The reserved-segment guard does NOT apply here —\n    this helper is the privileged writer that the guard is protecting.\n    \"\"\"\n    component = FileSystemToolComponent()\n    if user_id is not None:\n        component._user_id = user_id  # noqa: SLF001 — privileged binding seam\n    try:\n        sandbox_root = component._validate_root()  # noqa: SLF001\n    except PermissionError as exc:\n        # PermissionError from _validate_root happens in two cases:\n        # 1. AUTO_LOGIN=False and no user_id → translate to our domain error.","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/agentic/services/user_components.py#L225-L261","documentation":"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.","triggerScenarios":"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.","commonSituations":"LLM degenerate repetition during long streams; developers embedding large lookup tables or serialized model weights directly in component code instead of loading from storage.","solutions":["Move large embedded data out of the component and load it from file storage or a URL at runtime.","If the code is a runaway model output, regenerate with a shorter max-length constraint.","As a last resort raise MAX_COMPONENT_SOURCE_BYTES in your fork — but 1 MiB signals something wrong with the input."],"exampleFix":"# before\ncode = 'class Big:\\n    DATA = \"' + base64.b64encode(huge_file).decode() + '\"'\nregister_user_component(user_id=uid, class_name=\"Big\", code=code)\n\n# after\ncode = 'class Big:\\n    def load(self):\\n        return download_or_read_from_storage(\"big.bin\")'\nregister_user_component(user_id=uid, class_name=\"Big\", code=code)","handlingStrategy":"validation","validationCode":"MAX_BYTES = 1 * 1024 * 1024\n\ndef code_within_limit(code: str) -> bool:\n    return len(code.encode(\"utf-8\")) <= MAX_BYTES","typeGuard":null,"tryCatchPattern":"try:\n    register_user_component(user_id=uid, class_name=name, code=code)\nexcept UserComponentError as e:\n    if \"exceeds limit\" in str(e):\n        code = truncate_or_externalize(code)  # move data blobs out","preventionTips":["Constrain model output max_tokens for component generation.","Never embed base64/data URIs in component source; load data at runtime.","Check encoded byte size (not character count) before registering."],"tags":["validation","size-limit","user-components","llm-output"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}