{"record":{"id":"8bd3363e9406ade6","repo":"crewAIInc/crewAI","slug":"pdf-filename-page-count-page-count-exceeds","errorCode":null,"errorMessage":"PDF '{filename}' page count ({page_count}) exceeds maximum ({constraints.max_pages})","messagePattern":"PDF '(.+?)' page count \\((.+?)\\) exceeds maximum \\((.+?)\\)","errorType":"validation","errorClass":"FileValidationError","httpStatus":null,"severity":"error","filePath":"lib/crewai-files/src/crewai_files/processing/validators.py","lineNumber":326,"sourceCode":"    errors: list[str] = []\n    content = file.read()\n    file_size = len(content)\n    filename = file.filename\n\n    _validate_size(\n        \"PDF\", filename, file_size, constraints.max_size_bytes, errors, raise_on_error\n    )\n\n    if constraints.max_pages is not None:\n        page_count = _get_pdf_page_count(content)\n        if page_count is not None and page_count > constraints.max_pages:\n            msg = (\n                f\"PDF '{filename}' page count ({page_count}) exceeds \"\n                f\"maximum ({constraints.max_pages})\"\n            )\n            errors.append(msg)\n            if raise_on_error:\n                raise FileValidationError(msg, file_name=filename)\n\n    return errors\n\n\ndef validate_audio(\n    file: AudioFile,\n    constraints: AudioConstraints,\n    *,\n    raise_on_error: bool = True,\n) -> Sequence[str]:\n    \"\"\"Validate an audio file against constraints.\n\n    Args:\n        file: The audio file to validate.\n        constraints: Audio constraints to validate against.\n        raise_on_error: If True, raise exceptions on validation failure.\n\n    Returns:","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-files/src/crewai_files/processing/validators.py#L308-L344","documentation":"validate_pdf counts pages (when pypdf is available for probing) and raises FileValidationError when page_count > constraints.max_pages; the message shows both numbers. It runs after the size check, only when max_pages is set and the count could be determined.","triggerScenarios":"Validating a multi-page PDF (e.g. 120 pages) against PDFConstraints(max_pages=50) with raise_on_error=True, or processing it through FileProcessor in STRICT mode. Documents within the limit pass through untouched.","commonSituations":"Long manuals, contracts, or scanned reports exceeding provider context limits; constraints set to match a model's per-request page budget; concatenated PDFs created by a scanner feeding many documents into one file.","solutions":["Use FileHandling.CHUNK so the processor splits the PDF into max_pages-sized chunks (with overlap) instead of failing — requires pypdf.","Split the PDF upstream (PdfWriter page ranges) before ingestion.","Raise max_pages if the provider/model can actually handle more pages.","Catch FileValidationError and report the page counts to the user."],"exampleFix":"# before\nconstraints = PDFConstraints(max_pages=50)\nvalidate_pdf(big_pdf, constraints)  # FileValidationError: 120 pages exceeds maximum 50\n\n# after\nfrom crewai_files.processing.enums import FileHandling\nprocessor = FileProcessor(constraints=constraints, handling=FileHandling.CHUNK)\nchunks = processor.process(big_pdf)  # split into ~50-page chunks instead of raising","handlingStrategy":"validation","validationCode":"from pypdf import PdfReader\n\npage_count = len(PdfReader(io.BytesIO(content)).pages)\nif constraints.max_pages is not None and page_count > constraints.max_pages:\n    return chunk_or_split(file, page_count, constraints.max_pages)","typeGuard":null,"tryCatchPattern":"from crewai_files.processing.exceptions import FileValidationError\n\ntry:\n    processor.process(pdf_file)\nexcept FileValidationError as e:\n    if \"page count\" in str(e):\n        # switch this file to CHUNK handling instead of STRICT\n        return FileProcessor(constraints=constraints, handling=FileHandling.CHUNK).process(pdf_file)\n    raise","preventionTips":["Use CHUNK mode for PDFs that may exceed max_pages (pypdf required).","Count pages (pypdf) before validation when page budget matters.","Split large documents upstream per chapter/section."],"tags":["validation","pdf","pages","constraints","chunking"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}