Est.

Extracting Contact Data From LLM-Structured Web Scrapes

LLMs replace fragile selectors with schema-driven extraction that adapts across layout variants.

· 9 min read · Updated
Cover illustration for “Extracting Contact Data From LLM-Structured Web Scrapes”
B2B Data Enrichment · September 30, 2026 · 9 min read · 2,102 words

The old approach required site-specific CSS or XPath selectors that had to be manually maintained through every redesign. The dominant change in contact data extraction is schema-driven LLM extraction: declare the fields you want, hand the model the page, and let it resolve whatever layout chaos sits in between.

The old approach asked engineers to write site-specific CSS or XPath selectors, then babysit them through every redesign, then build separate logic for every format quirk a contact field could take, emails tucked into mailto: links versus sitting as plain text, phone numbers with country codes or without, names buried deep in a bio paragraph. That's the baseline condition of the web, not a handful of edge cases.

At scale, this setup doesn't bend, it breaks. Any list of target companies worth scraping at volume means handling dozens of layout variants, each with its own quirks, under one pipeline.

Schema-driven extraction flips the instruction set. Instead of writing imperative code that walks a specific DOM tree, you define the output structure you want, pass in cleaned page content, and get back conformant JSON, while the model absorbs the job of figuring out how to get there across however many layouts it encounters. That shift is possible at production scale because structured output mode, JSON mode, function calling, tool use, is now standard across the major LLM providers, so the output of this step is a typed, validatable object rather than a wall of text that still needs a second parser to make sense of it. What's left is making sure the schema is built right and the output can be trusted, a validation problem now.

What a contact extraction schema must specify

The schema is the first real engineering decision in this pipeline, not paperwork that gets filed after the important work is done. A minimal, working contact extraction schema needs to cover full name, job title, company name, email address, phone number with a normalization hint, a LinkedIn or profile URL, and location, with every one of those fields typed and annotated rather than left as loose strings. For teams building go-to-market or sales-intelligence pipelines, that schema often grows: industry code, employee headcount band, open roles, tech-stack signals, and buyer-title keywords all get added, each constrained so the model pulls from what's actually on the page instead of guessing or inventing.

Pydantic in Python and Zod in TypeScript are the natural tools for this job, because they do double duty: they define the shape of what you want extracted, and they validate the shape of what comes back. Think of a Pydantic model like a bouncer with a very specific guest list. It doesn't just wave people through the door, it checks every name against the list on the way out, too.

A contact schema in Pydantic might look like this:

from pydantic import BaseModel, Field
from typing import Optional

class Contact(BaseModel):
full_name: str = Field(description="The person's full name as written on the page")
job_title: Optional[str] = Field(default=None, description="Current job title or role")
company_name: Optional[str] = Field(default=None, description="Employer or organization name")
email: Optional[str] = Field(default=None, description="Email address, including mailto: links")
phone: Optional[str] = Field(default=None, description="Phone number in any format found on the page")
linkedin_url: Optional[str] = Field(default=None, description="LinkedIn or professional profile URL")
location: Optional[str] = Field(default=None, description="City, region, or office location")

Every one of those Field(description=...) lines is doing real work. It's not a code comment for the next engineer who opens the file, it's text that gets sent to the model as instruction, telling it what each field means and where on the page to go looking for it. Write phone: str with no description and a model might grab a fax number, a support line, or the area code scribbled into unrelated prose.

That matters more than it looks: a field marked Optional with a null default tells the model it's fine to return nothing when nothing's there, so you get a structured null back instead of the model silently dropping the field or inventing a plausible-sounding value to fill the gap. A missing field should read as null rather than a guess at what the value probably is.

Preparing page content before it reaches the model

Feeding raw HTML straight into an LLM is the single most common, and most avoidable, mistake in this entire pipeline. It's a bit like mailing someone a phone book to deliver a single phone number.

The fix is preprocessing: convert raw HTML into clean Markdown before it ever reaches the model.

This is a meaningful finding for anyone budgeting a production pipeline: the preprocessing step isn't just trimming costs at the margins, it changes which models are even worth considering for the job.

Markdown earns its place here because it sits in a useful middle ground. It's lightweight like plain text, but it still preserves the structural relationships, which email sits under which name, which title follows which bio, that contact extraction actually depends on. Token budgets deserve attention on a per-call basis, too.

Making the structured output call

Once the content is clean and the schema is defined, the actual LLM call passes a system prompt that sets the extraction role, the cleaned page content itself, and the JSON schema generated from the Pydantic model.

Structured output mode works differently than it sounds. Structured output mode constrains the model at the API level, so what comes back is JSON that matches the schema.

A working call looks something like this:


{"role": "system", "content": "Extract contact data from the provided page content. If a field cannot be determined, return null."},

What a model brings to this that a CSS selector never could is judgment. It maps a phone number written in parentheses and one written in international format to the same typed field. It connects an email address to a name mentioned two sentences earlier in the bio, something a selector built around DOM position has no way to do.

Model choice affects both cost and accuracy here. Per-page LLM extraction, which once looked like a research-lab luxury, is now a line item that fits inside a normal production budget.

## Validating and scoring the output before it enters any downstream system

Cloudflare's AI Labyrinth changed the stakes on validation. Instead of serving a scraper a block page when it detects bot-like behavior, it now serves back plausible-looking, AI-generated pages that read fine to a model but contain nothing real. A pipeline with no semantic validation layer will extract a confident, well-formatted contact record from one of those pages and ingest it straight into a downstream system, poisoned and none the wiser.

That's the clearest argument for treating validation as required infrastructure rather than a cleanup step tacked on at the end. A model can return a string sitting in the `email` field that isn't a valid email address at all, or a full name that reads naturally but never actually appeared anywhere on the source page.

Two layers of validation belong in every contact extraction pipeline. Semantic validation asks something harder: does the extracted value actually look like what the field claims it is? That means running an email format check, normalizing and sanity-checking the phone number, and confirming a URL resolves to something real rather than a dead or fabricated link.

The output of validation shouldn't be a binary pass or fail. It should produce a confidence tier or quality flag attached to each record, so a system downstream can route the shaky, low-confidence records to a human reviewer instead of either silently discarding them or, worse, letting them flow straight into a CRM as if they were solid.

## Access infrastructure: what the schema layer cannot solve

None of the schema design or validation logic matters if the pipeline never gets a real page to read in the first place. Schema-driven LLM extraction solves the parsing problem well, but it has nothing to say about the access problem. Anti-bot systems check network behavior, browser fingerprints, session patterns, and traffic consistency, and none of those systems care how elegant the extraction layer sitting behind them happens to be.

The right architecture treats access as its own tier, separate from extraction entirely. Anti-bot bypass gets reserved for the sites that actually require it, matched per-request rather than applied as a blanket policy across every target.

This is an architectural choice, not a commodity purchase, and the cost differential makes that obvious. Tiering access by what each site actually demands keeps the bill proportional to the difficulty, and it means a pipeline doesn't buy a sledgehammer to open every single envelope.

## Hybrid architecture: where deterministic extraction still outperforms LLMs

The strongest objection to an LLM-first pipeline isn't about law or ethics. It's architectural: AI extraction earns its cost only when it's used selectively, with deterministic crawling, access management, and validation surrounding the LLM call rather than getting replaced by it.

At enterprise volume, teams routinely report spending 30 to 40 percent of their data engineering hours just keeping scrapers running. That figure says something important: the cost of orchestrating all the moving pieces in a scraping pipeline has overtaken the cost of the pieces themselves. Piling more LLM calls onto a pipeline that already lacks architectural discipline doesn't fix that problem, it compounds it.

Deterministic selectors still win, clearly, on stable, high-volume, high-stakes fields. A known email format sitting in a known DOM position, a phone number wrapped in a `tel:` link, these don't need semantic understanding, and running them through a model just adds cost per token for no real benefit. LLM extraction earns its keep elsewhere: unstructured bios where a name and title sit buried in a paragraph, target lists where layouts vary site to site, and fields that genuinely require judgment, like whether a listed person counts as a decision-maker or what scope their role actually covers.

The mature version of this architecture runs deterministic extraction first, falls back to LLM extraction only for fields that fail or pages where selector confidence drops low, and routes both paths through the same validation layer so nothing downstream has to know which method produced a given record. They just don't belong on every call.

## Scaling the pipeline: batching, monitoring, and data freshness

A contact extraction pipeline is never a one-time job, because contact data decays. People change jobs, companies restructure, phone numbers get reassigned, and a dataset that was accurate in January can be meaningfully stale by summer. That means the pipeline needs to run on an ongoing refresh cadence, not just at initial build.

Running this across thousands of URLs changes the architecture again. Synchronous, per-request calls accumulate latency and cost in ways that get unpredictable fast at that volume. A pipeline built for scale needs webhook-triggered async processing, proper queue management, and cost tracking broken out per batch rather than per call.

Monitoring needs to work on two separate levels. Data-quality monitoring asks a harder question: are the extracted fields passing validation, and is the contact data shifting in ways that suggest the source page itself changed underneath the pipeline.

Schema drift is the failure mode most teams underestimate. A target site restructures its contact page, the LLM keeps extracting without complaint, but it's now quietly mapping the wrong fields into the wrong slots. The accuracy just drops, silently, and the only way to catch it is by monitoring extracted data against the field distributions the pipeline expects to see.

NielsenIQ's digital shelf analytics operation is a useful picture of what unmanaged scale actually costs. Scale without pipeline discipline doesn't stay an engineering problem for long. It turns into a staffing problem, and those are a lot more expensive to fix.

## The compliance constraint that makes contact extraction legally distinct from other web data

Scraping a product price or a product description deals in information that belongs to no one in particular. A schema that outputs `email` and `phone` fields isn't just producing structured data, it's producing personal data, and personal data carries legal weight that a product SKU never will.

None of the engineering discipline covered so far, the schema, the preprocessing, the validation layer, the access tiering, the hybrid fallback, substitutes for that compliance layer. A well-validated email address extracted and stored in violation of applicable data protection rules is still a liability, no matter how clean the JSON looks coming out of the model. The schema defines what gets extracted. Compliance defines what's allowed to happen to it next, and that second question sits outside the pipeline's architecture entirely, answered by legal and policy decisions rather than by better prompts or stricter Pydantic types.

Sources

  1. LLM-Powered Data Extraction: Schema-Driven Scraping with Structured Output | ByteTunnels
  2. The Complete Guide to Using Pydantic for Validating LLM Outputs - MachineLearningMastery.com
  3. How to get structured output from LLM's - A practical guide | AWS Builder Center
  4. Prompting for Data Extraction: Structured Output Guide 2025
  5. Beyond BeautifulSoup: Benchmarking LLM-Powered Web Scraping for Everyday Users

More in B2B Data Enrichment