skip to content

data pipeline and data quality · lesson 4 of 9 · sources checked 2026-11-22

validity checks on extracted data

This lesson gives a ladder of checks for size, count, structure, type, and vocabulary, and a counter for each reason that rejects a record.

status of this lesson: documented in my test system

purpose

A response with status 200 and some data looks like a success. But the page can be a block page, an empty template, or plausible content with wrong values. If no check reads the content, the store fills with bad records, and each chart that reads them is wrong.

objectives

  1. Write validity checks for extracted data: size, count, structure, type, and vocabulary.
  2. Explain why a success code is not proof of usable content.
  3. Count each rejected record by its reason.
  4. Reject a stored URL that has a scheme other than http or https.

new terms

count deviation
The absolute difference between the extracted record count and the count that the page structure gives, divided by the expected count.
prompt injection
Text in the model input that tries to change the instructions that the model obeys.

how it works

A record is valid only when its content is correct and the data has the expected size. I use one ladder of checks. Each check finds one failure class:

checkwhat it readsfailure class that it finds
StatusThe status codeA hard error or a refusal
SizeThe length of the bodyAn empty or short page
CountThe record count against the page structureLost records, or a page with no real content
StructureEach mandatory fieldA change of the page form
Type and vocabularyThe type and the set of permitted valuesA bad value or a bad URL scheme
baseline diffThe values against a capture of high trustPlausible but wrong content

The first checks cost little, and the last checks find more. A record goes to the store only when it passes each check.

a success code is not content

A soft block is a response with a normal status that holds no real content or less content. For example, a page returns status 200 with the text "Please try again later" in place of a product list. The status check passes, but the page has no record.

The first chart in the section "Data" shows this gap.

Thus a pipeline that counts fetched pages reports a success that it does not have. The correct count is the count of pages with usable content. Each failure also saves a copy of the page, so that a later check can read it again.

the generic check of the benchmark platform

The benchmark platform, my test system, has a render floor. This generic check reads the status, the size of the body, and a title or a count of nodes.

The floor gives pass when no site definition exists and no block signature fires. Thus a soft-block page with a title and enough text passes the floor. The floor is only the first steps of the ladder. A site definition with a count check and a structure check must follow it.

The same system has two guards before a write:

  • A vector with a value that is not finite, for example NaN, can damage each similarity search that touches it. Thus the writer rejects it, and logs the reference of the item and the length of its text.
  • A value from a classify step goes into a typed column only if the catalog holds it. The match uses whole words, never a part of a longer word.

count against the page structure

The page itself gives the count of records to expect. For example, a list page shows 24 product tiles. The extractor must give 24 records. When it gives 3 records, or 0, the page changed or the content is not real.

The count deviation is the absolute difference between the extracted count and the count that the page structure gives, divided by the expected count. A deviation of 0 is the goal, and a deviation above a set limit rejects the page.

type and vocabulary

Each field has a type and, where possible, a set of permitted values. For example, a currency field accepts only codes of a fixed list, such as EUR and USD. A price is a finite number of 0 or more.

A value outside the set is a rejection with its own reason. It never becomes a guess.

An absent value stays null. A rejected value is not an absent value. The record goes to the rejection count with its reason, not to the store with a null.

a stored url gets a scheme check

A feed can hold a link with the scheme javascript:. Such a link is hostile content. If a page of the reader shows it, a click runs code. Thus the writer checks the scheme of each stored URL at the time of the write.

The writer accepts only http and https, and it rejects all other schemes with the reason "bad URL scheme".

text that gives an instruction to a model

Text in a feed can also hold an instruction for a language model. When a model later reads the record, the text can try to change the instructions of the model. This is prompt injection that comes in through the data.

For example, a product description holds the line "ignore the rules above". A validity check cannot find it alone. The test suite is in A prompt-injection test suite (not yet published).

the quality metrics of one extractor

I keep three metrics for each extractor:

  • the null rate of each field, for each period;
  • the count deviation against the page structure;
  • the rejected records, with a counter for each reason.

The second chart in the section "Data" shows the first metric for one pipeline of news records. Three groups of fields have very different null rates, and each rate changes from month to month. The stored data has no count deviation and no rejected records. Thus that chart shows only the null rate.

the last check: a trusted control

A trusted control is a capture from a channel of high trust that the system compares with a fleet capture.

A baseline diff compares the attempt with the trusted control by structure and by field values. It is the only check that finds plausible but wrong values. For example, all prices on a page are 10% higher than the prices of the trusted control.

the two sides

automation sidedetection side
Check the size, the count, and the structure of each record against the page structure. Reject numbers that are not finite and values outside the vocabulary before the write.A defender can serve a page with plausible but wrong content. Only checks on the content find this. Status checks do not.

design decisions

optiongaincostwhen it is correct
Status check onlySimple and fastA soft block and wrong content passNever as the only check
A generic floor (status, size, title or node count)Works with no site definitionA soft-block page with enough text passesAs the first steps, before a site definition
Count and structure checks for each siteFinds lost records and a changed page formA site definition for each targetEach target that a chart or a reader of the data uses
Type and vocabulary checksNo bad value reaches a typed columnA list of permitted values to keepEach field with a closed set or a numeric type
Baseline diff against a trusted controlFinds plausible but wrong valuesA second capture from a channel of high trustA sample of pages, and each page that a check flags
Reject with a reason counterEach fault shows as a rise of one reasonOne counter for each reasonEach validator

diagram

The first diagram shows the ladder of checks.

the ladder of validity checks, with the failure class that each check finds

The cheap checks come first. A record that fails a check goes to the counter of its reason, never to the store.source: My model of the ladder of validity checks

The second diagram shows where the guard on values that are not finite stands in the ingest of documents. More detail on that ingest is in Dedupe keys and idempotent ingest (not yet published).

ingest of documents with a content hash, a vector guard, and a breaker

An unchanged document costs one lookup. An open breaker defers a document and does not fail it.source: My model of the ingest of documents with guards

code example

The example uses synthetic records of one lab list page. It reads no network.

m27-x08-validator.pypython

Check each extracted record for the mandatory fields, the type, the vocabulary, and the URL scheme. Check the record count against the count of the page structure. Count each reason that rejects a record.

import json
import math
import sys
from collections import Counter

# Argument 1: the count of records that the page structure shows, for example 6.
expected = int(sys.argv[1])
MANDATORY = ("title", "price", "currency", "scheme", "path")
CURRENCIES = {"EUR", "USD"}
SCHEMES = {"http", "https"}
MAX_DEVIATION = 0.1

records = [
    {"title": "item 1", "price": 12.5, "currency": "EUR", "scheme": "https", "path": "/item/1"},
    {"title": "item 2", "price": float("nan"), "currency": "EUR", "scheme": "https", "path": "/item/2"},
    {"title": "item 3", "price": 8.0, "currency": "eur0", "scheme": "https", "path": "/item/3"},
    {"title": "item 4", "price": 3.0, "currency": "USD", "scheme": "javascript", "path": "void(0)"},
    {"title": "item 5", "currency": "USD", "scheme": "https", "path": "/item/5"},
]

def reason(r):
    for field in MANDATORY:
        if field not in r:
            return "missing:" + field
    if not isinstance(r["price"], (int, float)) or not math.isfinite(r["price"]) or r["price"] < 0:
        return "type:price"
    if r["currency"] not in CURRENCIES:
        return "vocab:currency"
    if r["scheme"].lower() not in SCHEMES:
        return "scheme:url"
    return None

reasons = Counter()
accepted = []
for r in records:
    why = reason(r)
    if why is None:
        accepted.append(r)
    else:
        reasons[why] += 1

deviation = abs(len(records) - expected) / expected
page_state = "reject page" if deviation > MAX_DEVIATION else "page ok"
print(json.dumps({"expected": expected, "extracted": len(records),
                  "deviation": round(deviation, 3), "page": page_state}))
print(json.dumps({"accepted": len(accepted), "rejected": dict(sorted(reasons.items()))}))

I did not run this code. Thus the page shows no output.

The code gives each rule of the ladder its own reason:

  • a missing field;
  • a price that is not a finite number of 0 or more;
  • a currency outside the list;
  • a URL with a scheme other than http or https.

The page gets a reject when the count deviation is above the limit.

data

reported success and usable content for two clients on 15 invented page classes

status of this figure: measured by me

reported success and usable content for two clients on 15 invented page classesreported successhttp client73.3%browser73.3%unit: %usable contenthttp client13.3%browser20%unit: %

lines: interval, level 0.95

source: Lab result of this course: 15 invented page classes on a lab server, two clients; date 2026-11-15; sample of 600; condition: The page classes are invented and the pages are on my own page server. Lab teaching values for one host.

data table
reported success and usable content for two clients on 15 invented page classes
seriesclient%interval
reported successhttp client73.369.7 to 76.7 (level 0.95)
reported successbrowser73.369.7 to 76.7 (level 0.95)
usable contenthttp client13.310.8 to 16.3 (level 0.95)
usable contentbrowser2017 to 23.4 (level 0.95)
Each client fetched 15 page classes, 40 times each. The classes have equal weights, thus the lab cannot show the mix of real sites. Usable content came from 2 classes for the http client and 3 for the browser.

The first chart is a lab result with invented page classes. It is not a rate of real sites. Its point is the gap between the two bars of each client: a success code says little about the content.

null rate of fields of the news records, by month of creation

status of this figure: measured by me

null rate of fields of the news records, by month of creation30.4%13%18.3%22.7%21.8%95.7%54.4%74.2%85.1%83.2%99.6%88%94%100%100%abcde%1. entity type, entity ID, event type2. trust weight, first-party delta3. affected site counta. 2026-07b. 2026-08c. 2026-09d. 2026-10e. 2026-11 (part month)

lines: interval, level 0.95

source: Benchmark platform, data (my test system): news records of one extractor pipeline, null rate of each field; date 2026-11-03; sample of 5,849; condition: Intervals are 95% at record level. The data has no count deviation and no rejected records.

data table
null rate of fields of the news records, by month of creation
seriesmonth of creation%interval
entity type, entity ID, event type2026-0730.428.5 to 32.4 (level 0.95)
entity type, entity ID, event type2026-081311.4 to 14.8 (level 0.95)
entity type, entity ID, event type2026-0918.316.2 to 20.7 (level 0.95)
entity type, entity ID, event type2026-1022.720.1 to 25.5 (level 0.95)
entity type, entity ID, event type2026-11 (part month)21.814.8 to 30.8 (level 0.95)
trust weight, first-party delta2026-0795.794.8 to 96.5 (level 0.95)
trust weight, first-party delta2026-0854.451.9 to 56.9 (level 0.95)
trust weight, first-party delta2026-0974.271.6 to 76.7 (level 0.95)
trust weight, first-party delta2026-1085.182.6 to 87.2 (level 0.95)
trust weight, first-party delta2026-11 (part month)83.274.7 to 89.2 (level 0.95)
affected site count2026-0799.699.3 to 99.8 (level 0.95)
affected site count2026-088886.3 to 89.6 (level 0.95)
affected site count2026-099492.4 to 95.2 (level 0.95)
affected site count2026-1010099.6 to 100 (level 0.95)
affected site count2026-11 (part month)10096.3 to 100 (level 0.95)
Over all months, entity type, entity ID, and event type are null in 22.2% of 5,849 records. Trust weight and first-party delta are null in 78.9%. Affected site count is null in 95.6%. The last month is a part month.

The second chart comes from stored records of the benchmark platform. A field with a high null rate in each month is a field that the extractor almost never fills. Before a chart uses such a field, the null rate must be known.

failure modes

problemcausecorrection
The report shows a high success rate, but the store has few records.The count uses the success code, not the usable content.Count the pages with usable content, and save a copy of the page on each failure.
A block page passes as a success.Only the generic floor reads the page, and the block page has a title and enough text.Add a count check and a structure check for each site.
Each similarity search gives bad results.One vector with a value that is not finite went into the store.Reject values that are not finite before the write, and log the reference and the text length.
Links to entities that do not exist fill the store.A free-text value went into a typed column.Write a value into a typed column only if the catalog holds it. Match whole words.
A link in a page of the reader runs code.A stored URL has the scheme javascript:.Check the scheme of each URL at the time of the write.
A fault of the extractor stays hidden.The validator rejects records but does not count the reasons.Keep a counter for each reason, and look for a rise of one reason.

check questions

  1. A list page shows 20 product tiles. The extractor gives 2 records, and the status is 200. Which check finds the fault?

    1. The status check
    2. The count check against the page structure
    3. The URL scheme check
    4. No check, because the status is 200
    answer

    b. The count check against the page structure

    The page structure gives the count of records to expect. A count far below it shows lost records or a page with no real content.

  2. Explain why a response with status 200 is not proof of usable content.

    sample answer

    A soft block has a normal status and holds no real content or less content. A generic floor that reads the status, the size, and a title can also pass such a page. Only checks on the content, for example a count check and a structure check, find it. Thus a pipeline counts the pages with usable content, not the fetched pages.

  3. A validator rejects records but keeps only one total of rejections. What do you lose?

    1. The count of accepted records
    2. The status code of each page
    3. The rise of one reason that shows which part of the extractor is wrong
    4. Nothing, because a total is sufficient
    answer

    c. The rise of one reason that shows which part of the extractor is wrong

    A counter for each reason shows a fault as a rise of one reason. For example, the reason missing price rises after a change of the page form.

  4. A feed item holds a link with the scheme javascript. What does the writer do at the time of the write?

    1. It rejects the link with the reason bad URL scheme
    2. It stores the link, and the page of the reader removes it later
    3. It changes the scheme to https
    4. It stores the link as an absent value
    answer

    a. It rejects the link with the reason bad URL scheme

    The writer accepts only http and https. A link with another scheme is hostile content, because a click on it can run code.

exercise

exercise Do this task on paper. The records are synthetic. The page structure of a list page shows 5 product tiles. The rules are those of the code example:

  • mandatory fields: title, price, currency, scheme, and path;
  • currency: EUR or USD;
  • price: a finite number of 0 or more;
  • URL scheme: http or https;
  • count deviation limit: 0.1.

The extractor gives these 4 records:

recordtitlepricecurrencyschemepath
1item A4.0EURhttps/item/a
2item B-1.0EURhttps/item/b
3item C7.5GBPhttps/item/c
4(none)2.0USDhttps/item/d
  1. Write the reason for each record that the validator rejects.
  2. Write the counter of each reason.
  3. Calculate the count deviation of the page.
  4. Write if the page passes the count check.
sample answer

The answer uses the rules of the code example and the count deviation of "How it works".

Record 1 is accepted. Record 2 has the reason type:price, because the price is below 0. Record 3 has the reason vocab:currency, because GBP is not in the list. Record 4 has the reason missing:title. Each of the three reasons has a counter of 1.

The count deviation is (5 - 4) / 5 = 0.2. This is above the limit of 0.1. Thus the page fails the count check, and the validator rejects the page.

sources

  1. My model of the ladder of validity checks, the count deviation, and the quality metrics of one extractor, 2026-11 (not public).
  2. Benchmark platform, design (my test system): the generic render floor, 2026-11 (not public).
  3. Benchmark platform, code (my test system): the guard on values that are not finite, and the catalog check of a typed column, 2026-11 (not public).
  4. Lab result of this course: 15 invented page classes on a lab server, two clients, 2026-11 (not public).
  5. Benchmark platform, data (my test system): the null rate of each field of the news records, 2026-11 (not public).