Stay up to date with AI tools, model releases, and developer workflows that matter.
Weekly. Free. One click to leave.
7 Day Free Trial. Cancel Anytime.
AI powered scrapers have changed how a lot of teams collect web data. Instead of writing CSS selectors for every site, you describe the fields you want in a sentence and get structured JSON back. That is a real time saver, but it moves the risk somewhere upcoming. A selector either matches or it does not. A language model will almost always return something, and that something can be a value the page never contained.
This tutorial builds a small validation layer in Node.js that sits between an AI scraper and your database. It checks that each record has the fields you need, confirms every value actually appears on the source page, normalizes formats, and routes doubtful records to a review queue instead of straight into production.
According to recent reports, traditional scraping fails loudly. When a site changes its markup, your selectors return nothing and your job breaks. AI extraction fails quietly. If an author name is missing from a page, a model may fill the gap with a plausible guess, and the record looks perfectly healthy.
That is the same problem chat applications face. The SitePoint tutorial How to Reduce Hallucinations in LLMs demonstrates several fixes, including letting code make the final decision instead of the model. The idea carries over directly to scraping: the model proposes, your code verifies.
It also fits a wider point about data quality. Your AI Pipeline Works. But Can You Trust It? argues that a pipeline can run successfully and still produce wrong results when nobody checks the data flowing through it. Scraped data is a textbook case, because it comes from pages you do not control.
The OWASP Input Validation Cheat Sheet makes the security version of this argument: data from partner feeds, queues and other systems should be validated when it crosses a trust boundary. Output from a scraper, AI or not, crosses exactly that kind of boundary on its way into your database.
Before writing a validator, look at the shape of the data you will receive. A hosted tool such as Apify's AI Web Scraper describes returning each result with the page URL, the page content rendered as Markdown, and a data object holding the fields from your prompt. Its documentation also suggests telling the model to set fields the page does not show to null. That is the vendor's own description, so confirm the current documentation and test it against your own system before planning around it.
That combination is useful for validation. The data object is what you want to store, and the Markdown is the evidence you can check it against. The examples below assume results in that general shape, using a blog post with a title, an author and a publish date.
It has been revealed that start with a small schema that lists each field you asked for, whether it is required, and whether it needs special handling. Then write one function that checks a single result against it.
The function never throws. It returns a cleaned record plus a list of problems, so the caller decides what to do with each one. A null author is fine because the schema marks it optional, while a null title or publish date is flagged. This is why asking the model to return null for missing fields matters: an honest null is easy to handle, but a guessed value is not.
In a recent development, the most useful line in that function is the grounding check. For every value the model returned, it lowercases and collapses whitespace in both the value and the page Markdown, then confirms the value appears in the page text.
Industry observers note that this catches the quiet failure described earlier. If the model returns an author name that is nowhere on the page, the record is flagged as author: not on page instead of being stored as fact. It costs almost nothing to run, and it needs no second model call.
Pages write dates in every style imaginable, and your database should not inherit that mess. The date rule parses the value and stores it as YYYY-MM-DD. Using toLocaleDateString("en-CA") keeps the local calendar date, which avoids a common bug where converting to UTC with toISOString() shifts a date back by one day for anyone east of Greenwich.
Be aware that parsing free text dates with the Date constructor depends on the JavaScript engine. It handles formats like "March 3, 2026" in Node.js, but for production data from many sites, a dedicated date library with explicit formats is safer. The bad date problem gives you a clear signal when parsing fails, rather than a silently wrong value.
In a recent development, with the checker in place, routing results is a simple loop. Here it runs on two sample results, one honest and one with an invented author:.
Running node run.js puts the first post in accepted with its date stored as 2026-03-03. The second post lands in review with the problem author: not on page, because the page only highlights a publish date and the name John Smith was never on it.
According to recent reports, in production, the validator usually runs right after a scrape finishes. Many scraping platforms can call a webhook when a run completes, so your handler can fetch the results, pass each one through checkRecord(), write accepted records to the database and push the rest to a review table.
Two habits make this layer far more valuable over time. First, log the number of problems per run and per field. A sudden jump in not on page errors often means a prompt change or a site redesign, and you will see it before anyone notices bad data downstream. Second, keep the source URL and a copy of the Markdown with every review item, so whoever checks it can see exactly what the model was looking at.
The grounding check is deliberately strict, and that cuts both ways. It will flag correct values the model reformatted, such as a price written as "$1,200" on the page and returned as "1200". For fields like that, normalize both sides before comparing, or skip the page check and validate the type and range instead.
Recent findings suggest that it also cannot tell whether a value came from the right part of the page. A sidebar link to another article may contain a different author name that passes the check. For high value fields, add rules that reflect what you know about the data, such as allowed values, sensible date ranges or a match against a known list.
It has been revealed that A second model call adds cost and can make the same mistake twice. A plain string and type check in your own code is cheap, fast and gives the same answer every time, which makes failures easier to debug.
Usually not. Many flags are reformatting challenges rather than invented data. Sending them to a review queue keeps the data available while stopping it from reaching production unchecked.
No. A schema library is a good choice for types and formats as your records grow. The grounding check against the source page is the extra step that matters for AI extraction, and you can add it alongside whichever library you already use.
AI scrapers make extraction easier, but they can return values a page never contained. Define a small schema for the fields you need, treat honest nulls differently from missing required fields, check every value against the source Markdown, normalize formats before storage, and route anything doubtful to a review queue. The model does the reading, and your code decides what is trusted.
It has been revealed that 7 Day Free Trial. Cancel Anytime.
