Don't veto PDFCrawlerStrategy placeholder responses - #2138
Open
SohamKukreti wants to merge 1 commit into
Open
Conversation
PDFCrawlerStrategy returns stub html (real content comes from PDFContentScrapingStrategy), which the anti-bot checks misread as a block. Add AsyncCrawlResponse.placeholder_html so strategies can declare stub html and both anti-bot call sites skip it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PDFCrawlerStrategyreturns stub html (real content comes fromPDFContentScrapingStrategy), which the anti-bot checks misread as a block — every PDF crawl failed withBlocked by anti-bot protection: Near-empty content (33 bytes) with HTTP 200even though extraction succeeded, breaking the documented PDF workflow. The phantom "blocked" verdict also burned every configured retry/proxy attempt and pointlessly invokedfallback_fetch_functionon crawls that had already succeeded.Fix: add
AsyncCrawlResponse.placeholder_html(defaultFalse) so a crawler strategy can declare its html is a stand-in — mirroring the existingraw:-URL anddownloaded_filesexemptions — and skip both anti-bot call sites for flagged responses. Theis_blocked()heuristic itself is unchanged; responses without the flag behave exactly as before.Known limitation (disclosed): pairing
PDFCrawlerStrategywith a non-PDF scraping strategy now yields the placeholder text as content withsuccess=True; previously it produced a misleading anti-bot failure (wrong, but loud). Documented in thePDFCrawlerStrategydocstring.Fixes #2135
List of files changed and why
crawl4ai/models.py— addplaceholder_html: bool = FalsetoAsyncCrawlResponseso crawler strategies can declare stub html; defaultFalsekeeps every existing strategy unchanged.crawl4ai/processors/pdf/__init__.py—PDFCrawlerStrategy.crawl()setsplaceholder_html=Trueon its stub response; added a class docstring stating it must be paired withPDFContentScrapingStrategy.crawl4ai/async_webcrawler.py— skip the anti-bot classification in the attempt loop and the final anti-bot veto when the response declaresplaceholder_html(2 guard lines, alongside the existingraw:/downloaded_filesexemptions).tests/test_placeholder_html_antibot.py— new regression tests (network-free, generated local PDF fixture; integration tests skip cleanly viapytest.importorskip("pypdf")when the[pdf]extra is absent).How Has This Been Tested?
file://PDF with text extracted; no retry burn or fallback invocation withmax_retries=2and a spyfallback_fetch_function(attempts == 1,resolved_by == "direct");placeholder_htmldefaults toFalse;is_blocked()still flags near-empty html (heuristic unchanged).Blocked by anti-bot protection: Near-empty content (33 bytes)) and showing pre-fix code exhausting all retry attempts and invoking the fallback.arun_manyover multiple PDFs; failures stay loud (HTML bytes through the PDF pipeline, password-protected PDFs); normal browser crawls unchanged; a genuinely near-empty HTML page is still vetoed (the exemption is opt-in, not a bypass); theraw://exemption still works.tests/regression/— 309 passed, 0 regressions (1 pre-existing failure from the missing optionaltransformersextra, unrelated).docs/md_v2/advanced/pdf-parsing.md(the issue's repro) now returnssuccess=Truewith full extracted markdown.Checklist: