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 systempurpose
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
- Write validity checks for extracted data: size, count, structure, type, and vocabulary.
- Explain why a success code is not proof of usable content.
- Count each rejected record by its reason.
- Reject a stored URL that has a scheme other than
httporhttps.
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:
| check | what it reads | failure class that it finds |
|---|---|---|
| Status | The status code | A hard error or a refusal |
| Size | The length of the body | An empty or short page |
| Count | The record count against the page structure | Lost records, or a page with no real content |
| Structure | Each mandatory field | A change of the page form |
| Type and vocabulary | The type and the set of permitted values | A bad value or a bad URL scheme |
| baseline diff | The values against a capture of high trust | Plausible 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 side | detection 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
| option | gain | cost | when it is correct |
|---|---|---|---|
| Status check only | Simple and fast | A soft block and wrong content pass | Never as the only check |
| A generic floor (status, size, title or node count) | Works with no site definition | A soft-block page with enough text passes | As the first steps, before a site definition |
| Count and structure checks for each site | Finds lost records and a changed page form | A site definition for each target | Each target that a chart or a reader of the data uses |
| Type and vocabulary checks | No bad value reaches a typed column | A list of permitted values to keep | Each field with a closed set or a numeric type |
| Baseline diff against a trusted control | Finds plausible but wrong values | A second capture from a channel of high trust | A sample of pages, and each page that a check flags |
| Reject with a reason counter | Each fault shows as a rise of one reason | One counter for each reason | Each validator |
diagram
The first diagram shows the ladder of checks.
the ladder of validity checks, with the failure class that each check finds
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
code example
The example uses synthetic records of one lab list page. It reads no network.
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
httporhttps.
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
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
| series | client | % | interval |
|---|---|---|---|
| reported success | http client | 73.3 | 69.7 to 76.7 (level 0.95) |
| reported success | browser | 73.3 | 69.7 to 76.7 (level 0.95) |
| usable content | http client | 13.3 | 10.8 to 16.3 (level 0.95) |
| usable content | browser | 20 | 17 to 23.4 (level 0.95) |
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
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
| series | month of creation | % | interval |
|---|---|---|---|
| entity type, entity ID, event type | 2026-07 | 30.4 | 28.5 to 32.4 (level 0.95) |
| entity type, entity ID, event type | 2026-08 | 13 | 11.4 to 14.8 (level 0.95) |
| entity type, entity ID, event type | 2026-09 | 18.3 | 16.2 to 20.7 (level 0.95) |
| entity type, entity ID, event type | 2026-10 | 22.7 | 20.1 to 25.5 (level 0.95) |
| entity type, entity ID, event type | 2026-11 (part month) | 21.8 | 14.8 to 30.8 (level 0.95) |
| trust weight, first-party delta | 2026-07 | 95.7 | 94.8 to 96.5 (level 0.95) |
| trust weight, first-party delta | 2026-08 | 54.4 | 51.9 to 56.9 (level 0.95) |
| trust weight, first-party delta | 2026-09 | 74.2 | 71.6 to 76.7 (level 0.95) |
| trust weight, first-party delta | 2026-10 | 85.1 | 82.6 to 87.2 (level 0.95) |
| trust weight, first-party delta | 2026-11 (part month) | 83.2 | 74.7 to 89.2 (level 0.95) |
| affected site count | 2026-07 | 99.6 | 99.3 to 99.8 (level 0.95) |
| affected site count | 2026-08 | 88 | 86.3 to 89.6 (level 0.95) |
| affected site count | 2026-09 | 94 | 92.4 to 95.2 (level 0.95) |
| affected site count | 2026-10 | 100 | 99.6 to 100 (level 0.95) |
| affected site count | 2026-11 (part month) | 100 | 96.3 to 100 (level 0.95) |
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
| problem | cause | correction |
|---|---|---|
| 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
A list page shows 20 product tiles. The extractor gives 2 records, and the status is 200. Which check finds the fault?
- The status check
- The count check against the page structure
- The URL scheme check
- 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.
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.
A validator rejects records but keeps only one total of rejections. What do you lose?
- The count of accepted records
- The status code of each page
- The rise of one reason that shows which part of the extractor is wrong
- 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.
A feed item holds a link with the scheme javascript. What does the writer do at the time of the write?
- It rejects the link with the reason bad URL scheme
- It stores the link, and the page of the reader removes it later
- It changes the scheme to https
- 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, andpath; - currency:
EURorUSD; - price: a finite number of 0 or more;
- URL scheme:
httporhttps; - count deviation limit: 0.1.
The extractor gives these 4 records:
| record | title | price | currency | scheme | path |
|---|---|---|---|---|---|
| 1 | item A | 4.0 | EUR | https | /item/a |
| 2 | item B | -1.0 | EUR | https | /item/b |
| 3 | item C | 7.5 | GBP | https | /item/c |
| 4 | (none) | 2.0 | USD | https | /item/d |
- Write the reason for each record that the validator rejects.
- Write the counter of each reason.
- Calculate the count deviation of the page.
- 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
- My model of the ladder of validity checks, the count deviation, and the quality metrics of one extractor, 2026-11 (not public).
- Benchmark platform, design (my test system): the generic render floor, 2026-11 (not public).
- 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).
- Lab result of this course: 15 invented page classes on a lab server, two clients, 2026-11 (not public).
- Benchmark platform, data (my test system): the null rate of each field of the news records, 2026-11 (not public).