← Back to blog

Six Quality Gates for Web Extraction: Stop Bad Pages From Poisoning Your LLM Pipeline

Ask a team scraping the web for an LLM pipeline what breaks, and they will name JavaScript-heavy sites and bot walls. What actually breaks is quieter: the page returns 200 OK, the API returns valid JSON, and weeks later you find cookie banners, navigation menus, and 43-word shells embedded in your vector database.

In a live run for this article, https://blog.cloudflare.com/ returned 43 words across two lines — a header and a stub — from an endpoint reporting success. A Wikipedia article returned 262 words of infobox fragments instead of the article itself. Both were 200 responses.

The fix is not a better parser. It is a set of quality gates between extraction and ingestion: cheap, deterministic checks that decide whether a page deserves a model's context window. This post builds that layer with the Markdownify API and OGSnap, and reports what the gates caught across twelve real URLs.

What we measured

Each URL went through GET /v1/markdownify and GET /v1/ogsnap. From the markdown we computed four signals: word count, headings, link-text share, and distinct-word share (a crude boilerplate detector).

Page Words Headings Link share Distinct words Verdict
docs.python.org/3/library/asyncio-task.html 5,867 10 3.9% 0.29 accept
simonwillison.net 5,783 12 6.6% 0.38 accept
react.dev/learn 1,816 1 1.5% 0.36 accept
github.com/astral-sh/uv 955 4 7.0% 0.53 accept
theverge.com 1,053 0 13.5% 0.61 review
stripe.com/pricing 671 0 0.0% 0.55 review
docs.astral.sh/uv/ 571 0 8.1% 0.56 review
developer.mozilla.org/…/Fetch_API 387 3 25.8% 0.55 review
en.wikipedia.org/wiki/Open_Graph_protocol 262 0 15.6% 0.59 missed
blog.cloudflare.com 43 1 0.0% 1.00 reject
example.com 25 0 0.0% 0.88 reject
news.ycombinator.com — — — — reject (HTTP 400)

Two rows stand out. The Verge homepage produced 1,053 words and zero headings — readable prose with the structure flattened, which matters if you chunk on headings. Mozilla's Fetch API page is a quarter link text: normal for reference docs, a red flag on a tutorial. No single threshold separates these cases.

Gate 1: the transport must be honest

Refuse to treat an error as content. The API's failure modes are explicit:

# Link-listing page: HTML exists, prose does not
curl -s "https://fetchapi.tech/v1/markdownify?url=https://news.ycombinator.com/"
# {"detail":"No content could be extracted from this page"}

# Blocked publisher
curl -s "https://fetchapi.tech/v1/markdownify?url=https://www.nytimes.com/"
# {"detail":"Could not fetch URL — page may be blocked or unreachable"}

Both return HTTP 400, not 200 with empty content. The trap is latency: a request for a non-existent path on a live host hung past 120 seconds in testing. Set a client timeout well below the gateway's, and treat 400 as terminal — retrying a page with no extractable prose only burns quota.

import requests, time

def extract(url: str, timeout: int = 45) -> dict | None:
    for attempt in range(3):
        try:
            r = requests.get("https://fetchapi.tech/v1/markdownify",
                             params={"url": url}, timeout=timeout)
        except requests.Timeout:
            return None                      # slow origin, don't retry blindly
        if r.status_code == 200:
            return r.json()
        if r.status_code == 429:             # quota, not a transient blip
            return None
        if 500 <= r.status_code < 600:
            time.sleep(2 ** attempt)
            continue
        return None                          # 400: bad or blocked URL
    return None

Gate 2: is there a document here?

Eighty words is our floor. Below that you are looking at a JavaScript shell, a redirect stub, a consent wall, or a placeholder domain — and no prompt rescues it. example.com (25 words) and the Cloudflare blog index (43 words) fail; every genuine document clears the bar by an order of magnitude. The gate runs on word_count alone, so it costs nothing extra.

Gate 3: structure tells you whether the parser understood the page

A long document with zero headings usually means the HTML was flattened: tables, card grids, and hero sections collapse into pipe characters and bare paragraphs. Both docs.astral.sh/uv/ (571 words) and stripe.com/pricing (671 words) show this. Not garbage, but not chunkable either — heading-aware splitting has nothing to split on.

The same gate catches the opposite failure: 25.8% link text is expected on a reference page, but on a tutorial it means you extracted navigation. Use 22% as a soft signal and 35% as a hard fail.

import re

def structure_signals(md: str) -> dict:
    words = md.split()
    lines = [l.strip() for l in md.splitlines() if l.strip()]
    link_words = sum(len(t.split()) for t in re.findall(r"\[([^\]]+)\]\([^)]+\)", md))
    return {
        "words": len(words),
        "headings": len([l for l in lines if re.match(r"^#{1,6}\s", l)]),
        "link_share": link_words / max(len(words), 1),
        "distinct": len({w.lower() for w in words}) / max(len(words), 1),
        "fences": md.count("`" * 3),
    }

Check fence parity too. The GitHub README returned 30 markers — even, so blocks are balanced. An odd count means a fence opened and never closed, which breaks any downstream renderer.

Gate 4: repetition is boilerplate in disguise

Duplicate blocks — a "Subscribe to our newsletter" paragraph repeated down a feed, or a cookie notice captured once per card — are invisible in a word count and deadly in embeddings, because near-identical chunks crowd out real content in retrieval. Hash normalized lines over 25 characters and fail above a 25% repeat rate.

The Python docs page scored 0.29 distinct words and still passed, which is the point: API references repeat parameter names legitimately. Only fail when the distinct-word ratio and duplicate-line share agree. That page had one duplicate line in 99.

Gate 5: does the body match the page's own claim?

OGSnap returns the title the publisher wants Google to see. If the body never mentions its entities, you extracted a sidebar, a related-posts widget, or a different page after a redirect.

import re

STOP = {"the", "a", "an", "and", "or", "for", "to", "in", "on", "with",
        "your", "you", "how", "what", "why", "this", "that", "from"}

def topic_overlap(og_title: str, body: str) -> float:
    tokens = {t for t in re.findall(r"[a-z0-9]+", og_title.lower())
              if len(t) > 3 and t not in STOP}
    if not tokens:
        return 1.0
    body = body.lower()
    return sum(1 for t in tokens if t in body) / len(tokens)

Below roughly 0.34, send the page to review. Keep this soft: a legitimate page can discuss a concept without repeating its headline.

Gate 6: shape, not just size

The last gate compares extraction against expectations for that URL class. A docs index should be link-heavy; a tutorial should not. A product page is short; a Wikipedia article is thousands of words. This is where the Wikipedia row failed: 262 words of infobox fragments pass every numeric gate because they are well-formed text. Only an expected-length check flags it.

The cheapest implementation is a per-host baseline: store the median word count of accepted pages per hostname and flag anything under 25% of it. That is a few lines, and it catches most of the damage — which is why pipelines should persist extraction metrics, not just content.

Wiring the gates into a pipeline

Each verdict maps to a different action:

Cache on a content hash so unchanged pages cost nothing, and watch the request budget. Pairing OGSnap with every Markdownify call doubles consumption; on the free tier that turns a 50-request daily limit into 25 pages. Fetch OGSnap only when the body fails a gate, or once per URL and reuse the title for both the topic check and your link previews. A 429 returns {"detail":"Daily limit reached (50). Upgrade your plan."} with no Retry-After header — back off until the next window.

Finally, alert on failure rate per host, not per URL. One rejected page is noise; a host jumping from 5% to 60% means a redesign, a bot wall, or a parser regression — cheaper to fix on day one than after a month of bad embeddings.

The uncomfortable part

Gates are triage, not truth. The Wikipedia article passed five of six checks and was still wrong. You are not proving a page is good; you are making bad pages visible before they cost money.

Start with one transport rule, one word floor, one structure check, one repetition check, one topic check, and one shape check, then tune against your own corpus for a week. Keep the signals you compute — when retrieval quality drops six months from now, the answer will be in that table.

The endpoints above work from curl with no signup:

curl -s "https://fetchapi.tech/v1/markdownify?url=https://docs.astral.sh/uv/" | jq '.word_count'
curl -s "https://fetchapi.tech/v1/ogsnap?url=https://docs.astral.sh/uv/" | jq '{title, description}'

See the API docs for parameters and limits. For the ingestion side, the citation-first RAG walkthrough picks up where these gates leave off.