Skip to content

fix(pdf): raise clear error when fast strategy can't handle complex PDF - #4432

Open
Sohel2309 wants to merge 1 commit into
Unstructured-IO:mainfrom
Sohel2309:fix/pdf-fast-strategy-complex-pdf-4260
Open

fix(pdf): raise clear error when fast strategy can't handle complex PDF#4432
Sohel2309 wants to merge 1 commit into
Unstructured-IO:mainfrom
Sohel2309:fix/pdf-fast-strategy-complex-pdf-4260

Conversation

@Sohel2309

@Sohel2309 Sohel2309 commented Aug 12, 2026

Copy link
Copy Markdown

Summary

partition_pdf(..., strategy="fast") silently returns an empty element list — no exception, no warning — when the PDF trips the internal is_pdf_too_complex() heuristic.

This change raises a clear ValueError instead.

Fixes #4260

Problem

is_pdf_too_complex() exists to prevent pdfminer from running on documents where it performs poorly.

When the check fires, extraction is skipped and extracted_elements remains empty.

For strategy="auto", the existing strategy-selection logic can fall back to another strategy. However, when the user explicitly requests strategy="fast", the strategy remains fast, and the function eventually returns an empty list.

This results in a silent failure where the caller receives no elements and no explanation.

Solution

When is_pdf_too_complex() returns True and strategy="fast" was explicitly requested, raise a clear ValueError suggesting strategy="hi_res" or strategy="auto".

This preserves the existing complexity protection instead of bypassing it.

Normal fast PDFs and the existing auto behavior remain unchanged.

Tests

Added a regression test covering explicit fast strategy on a complex PDF.

The regression test fails with the previous behavior and passes with the fix.

Also verified the relevant PDF and strategy tests, along with Ruff formatting and lint checks.

Related Issue

Fixes #4260

Review in cubic

partition_pdf() skips pdfminer text extraction for PDFs flagged by
is_pdf_too_complex() as mostly vector graphics (e.g. CAD/engineering
drawings), since pdfminer is slow and unreliable on them.

For strategy="auto" this correctly falls back to another strategy.
But an explicitly-requested strategy="fast" has no fallback available,
so it silently returned an empty element list with no indication
anything went wrong.

This raises a ValueError in that case instead, explaining why and
suggesting strategy="hi_res" or strategy="auto". strategy="auto" is
unaffected and continues to fall back gracefully, and normal (non-
complex) PDFs with strategy="fast" are unaffected.

Fixes Unstructured-IO#4260

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Shadow auto-approve: would auto-approve. Focused bug fix: explicit fast strategy on a complex PDF now raises a clear ValueError instead of silently returning an empty list, with regression tests pinning the error and the preserved auto fallback. No new contract, schema, or operational tradeoffs introduced.

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug/partition_pdf() with stategy = "fast" is not extracting any elements

1 participant