{"record":{"id":"70192f6aa72ea96e","repo":"crewAIInc/crewAI","slug":"file-type-filename-size-format-size-file","errorCode":null,"errorMessage":"{file_type} '{filename}' size ({_format_size(file_size)}) exceeds maximum ({_format_size(max_size)})","messagePattern":"(.+?) '(.+?)' size \\((.+?)\\) exceeds maximum \\((.+?)\\)","errorType":"validation","errorClass":"FileTooLargeError","httpStatus":null,"severity":"error","filePath":"lib/crewai-files/src/crewai_files/processing/validators.py","lineNumber":186,"sourceCode":") -> None:\n    \"\"\"Validate file size against maximum.\n\n    Args:\n        file_type: Type label for error messages (e.g., \"Image\", \"PDF\").\n        filename: Name of the file being validated.\n        file_size: Actual file size in bytes.\n        max_size: Maximum allowed size in bytes.\n        errors: List to append error messages to.\n        raise_on_error: If True, raise FileTooLargeError on failure.\n    \"\"\"\n    if file_size > max_size:\n        msg = (\n            f\"{file_type} '{filename}' size ({_format_size(file_size)}) exceeds \"\n            f\"maximum ({_format_size(max_size)})\"\n        )\n        errors.append(msg)\n        if raise_on_error:\n            raise FileTooLargeError(\n                msg,\n                file_name=filename,\n                actual_size=file_size,\n                max_size=max_size,\n            )\n\n\ndef _validate_format(\n    file_type: str,\n    filename: str | None,\n    content_type: str,\n    supported_formats: tuple[str, ...],\n    errors: list[str],\n    raise_on_error: bool,\n) -> None:\n    \"\"\"Validate content type against supported formats.\n\n    Args:","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-files/src/crewai_files/processing/validators.py#L168-L204","documentation":"The shared size validator _validate_size (used by validate_image/validate_pdf/validate_audio/validate_video) raises FileTooLargeError when file_size > max_size. The exception carries structured fields: file_name, actual_size and max_size, and the message renders human-readable sizes via _format_size (e.g. 'Image \"photo.png\" size (8.0MB) exceeds maximum (5.0MB)'). In non-strict calls the message is only appended to the errors list.","triggerScenarios":"Validating any file whose byte size exceeds the constraint's max_size_bytes (e.g. ImageConstraints(max_size_bytes=5MB) with a 8MB upload) with raise_on_error=True (the default). Also reached via FileProcessor in STRICT mode after validate() collects the error.","commonSituations":"Provider hard limits (e.g. Anthropic/OpenAI request size caps) encoded as constraints, hit by high-resolution photos or scanned PDFs; user uploads from mobile cameras; constraints copied between projects with tighter limits than intended.","solutions":["Use the structured fields (e.actual_size vs e.max_size) to give the user a precise message and reject or compress.","Enable FileHandling.AUTO so oversized images are compressed (optimize_image) instead of rejected.","Raise max_size_bytes if the provider actually permits larger payloads.","For PDFs, use FileHandling.CHUNK to split by pages instead of failing on total size."],"exampleFix":"# before\nconstraints = ImageConstraints(max_size_bytes=5 * 1024 * 1024)\nerrors = validate_image(img, constraints)  # FileTooLargeError for 8MB image\n\n# after\nfrom crewai_files.processing.enums import FileHandling\nprocessor = FileProcessor(constraints=constraints, handling=FileHandling.AUTO)\nout = processor.process(img)  # compressed under the limit instead of raising","handlingStrategy":"validation","validationCode":"size = len(content)\nif constraints.max_size_bytes is not None and size > constraints.max_size_bytes:\n    return reject_or_compress(file, size, constraints.max_size_bytes)","typeGuard":null,"tryCatchPattern":"from crewai_files.processing.exceptions import FileTooLargeError\n\ntry:\n    processor.process(file)\nexcept FileTooLargeError as e:\n    msg = f\"'{e.file_name}' is {_fmt(e.actual_size)}; limit is {_fmt(e.max_size)}\"\n    return reject_upload(msg)","preventionTips":["Check file size client-side before upload.","Prefer FileHandling.AUTO so oversized images get compressed automatically.","Use the structured actual_size/max_size fields for precise user feedback."],"tags":["validation","file-size","constraints","filetoolargeerror"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}