AI-Assisted Extraction for Inconsistent Page Layouts
Semantic extraction makes web scraping resilient to layout changes.

AI-assisted extraction for inconsistent page layouts replaces brittle HTML addresses with a schema that describes what the data means. The practical fix combines semantic extraction with cleaning, validation, and bounded repair, so changes in page structure do not automatically become broken data.
Why selector-based scrapers fail on sites with inconsistent layouts
A developer spends three days building selectors, then the site gets redesigned on day four. The extraction code has not changed, but the assumptions it depends on have. A selector such as div.job-title points to a specific address in the HTML structure. When the site renames that class to position-heading, the selector returns nothing.
That failure is a structural mismatch. The scraper treats the page layout as a stable contract, while the website can change that layout through a redesign, an A/B test, or a CMS migration. The information may still be there for a reader to see. What has disappeared is the route the scraper used to reach it.
Fifty supplier pages mean fifty selector sets, each with its own ways to fail and its own schedule for upkeep. Fixing one does not make the others more reliable, because each set encodes a different page structure. Every change resets the clock on that selector’s reliability. The way out is to stop making the location of a field the only way to recognize it.
What semantic extraction actually does differently
Semantic extraction starts with the meaning of a field. Instead of specifying where to look, the developer specifies what to find. The instruction “extract job titles and locations” lets a model recognize “Chief Technology Officer” near a name and headshot as an executive title. That meaning can survive whether the text appears in a <div>, a <span>, or flowing prose.
One page might say “Our Price,” another “Sale Price,” and another “Member Price.” A schema can map those labels to a price field without needing a separate selector rule for each one. But the schema still has to make the intended meaning clear. Recognizing a price is not the same task as deciding which price the application needs.
There are three main implementation patterns, with different costs and resilience. In code generation, an LLM examines the HTML and produces a deterministic extraction script. That avoids ongoing LLM cost per page after generation, but layout changes require the code to be regenerated. It works well for sources with lots of pages whose layouts stay much the same.
Direct LLM extraction instead sends cleaned HTML or Markdown with a schema on every request. It suits variable layouts and ad-hoc extraction, at the cost of slower requests and per-page inference. Vision-based extraction passes a screenshot to a vision LLM, capturing what users see, including dynamic elements absent from the DOM. It is the slowest and most expensive pattern, but can serve as a verification layer for complex layouts.
How to design a schema that guides the model reliably
The schema is the main control over what the model extracts. A loose schema gives the model room to return something plausible but unusable. A narrow schema spells out more clearly what the answer should be and gives validation rules to check it against. The design question is therefore not only which fields the output should contain. It is also what counts as an acceptable value for each field.
A compact product schema can make that distinction concrete. The product name is a string, the price is a number, and availability is an enum limited to “In Stock” and “Out of Stock.” A price field typed as a string can accept text that does not belong in a numeric field. A number type makes that mistake detectable, while the availability enum prevents arbitrary wording from passing as a valid status. These constraints catch format errors, though they do not prove that the model read the right value.
Required fields need equally careful treatment. If a field must appear even when its value is absent, mark it as required and allow null explicitly. That makes missing information detectable through an explicit null value. The schema should preserve that distinction instead of pressuring the model to fill every field with a guess.
Few-shot examples help anchor the interpretation of ambiguous fields. Showing one correct extraction before asking for another gives the model a concrete pattern to follow on irregular pages. After extraction, run the JSON against the schema and retry on validation failure before treating a null or type error as the final result. Type checks, duplicate detection, confidence thresholds, and human review for sensitive fields keep deterministic checks around the model.
Where the approach breaks down and what to do about it
Nested divs, accordions, and inconsistent layouts can lead direct LLM extraction to guess what ought to be present. Schema validation alone can miss these mistakes because even a guessed price can be a number. The mitigation is worst-case testing on the pages the pipeline will actually face. A vendor’s tidy demo page cannot show how the system handles the hardest source.
Passing raw HTML straight into an embedding step fills chunks with menu labels, footer links, cookie notices, and hidden tabs. The substance is buried in noise, so retrieval can lead to half-right summaries. Preprocessing addresses this problem by removing navigation, ads, and scripts before the LLM or embedding step sees the content. Better extraction starts with a cleaner input.
Layout drift also needs a repair process with limits. When a price goes missing or a DOM region changes, capture the page and a previous successful sample. Ask the model to propose a repair within an allowlist, rather than giving it unrestricted control over the pipeline. Replay that proposal against labeled fixtures and reject it if precision or recall falls below the threshold. A repair that works on the changed page is not enough if it damages extraction elsewhere.
Deployment is the final boundary on that repair. Roll it out gradually with rollback available, so a proposed fix does not become an uncontrolled replacement. In a production system, “self-healing” means a bounded loop of detection, repair, testing, and release.
Building a pipeline that handles layout change without breaking
The architecture connects five stages, which are fetch, clean, extract, validate, and repair. Each stage handles a different source of error, so a model call cannot stand in for the whole pipeline. Fetch should begin with HTTP for static pages and use a headless browser when client-side script rendering is needed. Making that choice conditional controls cost. Rendering every page in a browser pays for work that some pages do not require.
Cleaning comes before either extraction or embedding. Remove navigation, ads, scripts, cookie notices, and footer links, then convert the remaining content to Markdown when a compact, model-readable representation is useful. Extraction then combines that cleaned content with the schema and few-shot examples. Narrow field types make the expected output explicit at the point where the model reads the page.
Validation separates a generated answer from an accepted record. Check the schema, types, and required fields, and apply confidence thresholds where fields are sensitive. Retry when a check fails before taking null as the result. This boundary matters because extraction and acceptance are different jobs.
Monitoring connects accepted records back to changes at the source. Store output with timestamps and compare the current extraction with the previous one. A missing field or a type error that keeps coming back should start the bounded repair loop. That turns the scraper from a script into a continuously maintained data product. For AI pipelines, the other payoff is that cleaned, structured output can feed embedding or retrieval without a second cleaning pass.
When to use an API that handles this pipeline rather than building it in-house
The initial extraction call is only part of the work. Proxy rotation, headless browser fleet management, DOM cleaning logic, schema versioning, and repair-loop tuning all require ongoing engineering attention. Compliance with evolving legal guidance adds another responsibility. For most teams, these tasks compete with the product the data was meant to support.
Extraction logic for a highly specific task may need controls that an API does not have. Strict latency requirements can also rule out services that take too long to respond. Regulatory constraints may prevent page content from going to a third-party service at all.
An API is the stronger choice when the team’s value lies in what it does with the data. Frequent layout drift makes that choice more pressing if selector maintenance already consumes a meaningful share of engineering time. The case also strengthens when the product needs several outputs, including Markdown content, structured JSON, and brand intelligence. Supporting them separately can turn a data pipeline into a collection of vendor integrations.
A crawler-only product can leave the team adding a logo API, a company enrichment provider, and a separate extraction step, each with its own authentication, rate limits, and failure modes. A unified API brings all those services under one contract. Integration speed is another practical signal, because reaching a working extraction call in minutes rather than days of infrastructure setup changes what can ship in a sprint. The decision is about which work the team needs to own.
Applying semantic extraction to the use cases where layout drift hurts most
Retrieval-augmented pipelines need current source material. A pricing page, product spec, or company leadership page can change while a model keeps saying what the old version said. Evaluations built around the old data may still pass, leaving no useful signal that the answer is stale. Semantic extraction with preprocessing provides a fetch layer for pipelines that must cite current sources. Its value here is keeping usable source content flowing when the page’s presentation changes.
Brand and company intelligence brings a different kind of variation. A sales or onboarding workflow may need a customer’s logo, colors, social profiles, and site copy across targets with different page templates. With selector rules, each template needs its own upkeep. Schema-driven extraction defines those outputs in the same way across sites, while a unified API can take the place of separate logo, enrichment, and extraction integrations.
Website change detection completes the loop. Crawl the page, store the output with timestamps, compare it with the previous version, and use an LLM to summarize meaningful changes before alerting. Visual differences alone produce false positives from rotating ads, cookie notices, and timestamps. Semantic filtering at the comparison stage separates those distractions from changes that matter to the pipeline.


