{"record":{"id":"c585d48607a88ade","repo":"datawhalechina/hello-agents","slug":"unsupported-input-file-format-source-path-suffix","errorCode":null,"errorMessage":"Unsupported input file format: {source_path.suffix}","messagePattern":"Unsupported input file format: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/healer-666-Academic-Data-Agent/src/data_analysis_agent/document_ingestion.py","lineNumber":252,"sourceCode":"        \"pdf_multi_table_mode\": True,\n        \"source_pdf\": source_pdf.resolve().as_posix(),\n        \"background_literature_context\": background_literature_context,\n        \"text_excerpt\": full_text_excerpt,\n        \"selected_table_id\": selected_table_id,\n        \"candidate_tables\": candidate_tables,\n        \"candidate_table_summaries\": candidate_tables,\n    }\n\n\ndef preview_pdf_tables(\n    data_path: str | Path,\n    *,\n    max_pdf_pages: int = 20,\n    max_candidate_tables: int = 5,\n) -> PdfPreviewResult:\n    source_path = Path(data_path).resolve()\n    if source_path.suffix.lower() not in SUPPORTED_DOCUMENT_SUFFIXES:\n        raise ValueError(f\"Unsupported input file format: {source_path.suffix}\")\n\n    scratch_root = source_path.parent / \".pdf_preview_tmp\"\n    scratch_root.mkdir(parents=True, exist_ok=True)\n    scratch_dir = Path(tempfile.mkdtemp(prefix=\"pdf_preview_\", dir=scratch_root))\n    try:\n        full_text, records = _extract_pdf_payload(\n            source_path,\n            max_pdf_pages=max_pdf_pages,\n            max_candidate_tables=max_candidate_tables,\n            extracted_tables_dir=scratch_dir,\n            persist_csv=False,\n        )\n    finally:\n        shutil.rmtree(scratch_dir, ignore_errors=True)\n\n    default_record = _select_primary_table(records)\n    warnings: list[str] = []\n    if records:","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/healer-666-Academic-Data-Agent/src/data_analysis_agent/document_ingestion.py#L234-L270","documentation":"`preview_pdf_tables` resolves the input path and immediately rejects it with ValueError unless its lowercased suffix is in SUPPORTED_DOCUMENT_SUFFIXES (the PDF-style document set). Message: 'Unsupported input file format: {suffix}'. This guards the table-preview entrypoint before any pdfplumber work starts.","triggerScenarios":"Calling preview_pdf_tables on a .csv/.xlsx (tabular, not a document — use the tabular path instead), on .docx/.png/.jpg, or on a scanned PDF stored with an odd extension; also fires for files with no extension.","commonSituations":"Users trying to preview tables inside Word documents or images; passing the wrong path variable (a cleaned CSV output instead of the source PDF); double extensions like .pdf.bak.","solutions":["Pass a file whose extension is in SUPPORTED_DOCUMENT_SUFFIXES (check that constant; typically .pdf).","For .csv/.xlsx inputs, skip document preview — they are already structured tables.","Convert .docx to PDF (e.g. via LibreOffice) before previewing tables.","Ensure the path points at the original source document, not a generated artifact."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef is_supported_document(path: str | Path, supported: set[str]) -> bool:\n    return Path(path).suffix.lower() in supported\n\n# before calling preview_pdf_tables\nif not is_supported_document(pdf_path, SUPPORTED_DOCUMENT_SUFFIXES):\n    raise ValueError(f\"preview needs a document file, got {Path(pdf_path).suffix}\")","typeGuard":null,"tryCatchPattern":"try:\n    preview = preview_pdf_tables(path)\nexcept ValueError as e:\n    if \"Unsupported input file format\" in str(e):\n        path = convert_to_pdf(path)  # e.g. LibreOffice export\n        preview = preview_pdf_tables(path)\n    else:\n        raise","preventionTips":["Route by type: tabular files (.csv/.xlsx) skip document preview entirely.","Convert office formats to PDF before table preview.","Import SUPPORTED_DOCUMENT_SUFFIXES from the package rather than hardcoding the set."],"tags":["validation","file-format","pdf","valueerror","python"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}