Data contracts between collectors and the analysts downstream

The price that changed meaning overnight

A collector team fixes a bug. On one retailer, the extractor had been picking up the crossed-out list price instead of the sale price on discounted items, so they point it at the right element and ship. The schema didn’t change. The field is still called price, still a decimal, still in the same currency. Every test passes.

The next morning, the pricing analyst’s week-on-week report shows that retailer cutting prices on hundreds of products overnight. It didn’t. The meaning of the field changed, from “whatever number the extractor found” to “the price a customer pays,” and nobody downstream was told. The analyst spends half a day proving it isn’t a real price move, then asks the question that matters: what else could change like this without warning?

That question is what a data contract answers. It’s a written agreement between the people who produce a dataset and the people who consume it, covering what each field is, what it means, when it can be empty, how fresh and complete the data will be, and how changes will be announced. It’s the consumer-facing half of the work covered elsewhere in this series. The versioning guide explains how the collector tracks its own output changes, and the schema-drift guide covers detecting when target sites change. This piece is about the agreement with the people who build on your output.

We produce scraped datasets for our own analysis and for other teams, and the contract is the document we’d write first if we started over. There’s nothing exotic in it. Most of its value comes from writing down things both sides assumed and didn’t share.

What a contract is and what it isn’t

A data contract has two parts. A machine-checkable part, which is the schema with types, required fields, allowed values and constraints, and a human part, which covers meaning and freshness, plus coverage, ownership and the change process. Both matter, and teams that only write the first get surprised by exactly the kind of change in the opening story, where the schema held and the meaning moved.

It isn’t a legal document, although if you’re delivering data to a paying client it may sit alongside one. It isn’t a promise that the data will be perfect. Scraped data depends on websites you don’t control, and a contract that pretends otherwise gets broken on the first redesign. And talking to consumers still comes first. The contract is the record of what you agreed when you talked.

The useful framing is that a contract turns implicit dependencies into explicit ones. Every consumer already depends on things about your output: that price includes tax, that a missing value means unavailable rather than unknown, that yesterday’s data is there by nine in the morning. They built dashboards and models on those assumptions. The contract writes them down, so the producer knows what it can’t change casually and the consumer knows what they can rely on.

It also makes disagreements cheap. When a consumer reads the contract and says “wait, we assumed prices were ex-tax,” that conversation costs ten minutes before anything is built. The same discovery after six months of reports costs a restatement.

Keep it short enough to read. A contract per dataset that runs to a few pages, with the schema in a file next to it, gets read. A fifty-page specification gets filed.

Why scraped data needs one more than most

Every data pipeline benefits from contracts. Scraped data needs them more, for three reasons that all come from the same fact: the collector doesn’t control its source.

In an internal pipeline, the producer team owns the upstream system, or can at least talk to whoever does. When a field changes, it’s because someone decided to change it. In collection, the upstream is a website run by someone who doesn’t know your pipeline exists, and changes arrive without notice or reason. The handover guide in this series puts it plainly: a scraper is a dependency on a website somebody else owns.

That means some changes to your output are forced on you. A site drops a field, restructures a price display, changes its product identifiers, or starts serving different content by region. The collector can detect and respond, but it can’t prevent. A contract for scraped data has to say what happens when that occurs, not pretend it won’t.

Consumers can’t see the source. An analyst looking at a sudden change in your data has no way to tell whether the world changed, the site changed, or your extractor changed. Only the producer knows, and only if it tracks it. The contract is where you commit to telling them which.

Scraped values are also more ambiguous than values from a system of record. A database column called price has one meaning, defined by the application that writes it. A price on a web page might be a list price, a sale price, a member price, a price per unit, a price before or after tax, a price for the cheapest variant, or a “from” price for a range. The extractor picks one. Unless the contract says which, every consumer guesses, and different consumers guess differently.

Fields and types, with units

The schema part of the contract starts with every field the dataset exposes: its name, its type, whether it’s required, and constraints on its values.

Types should be specific. A price is a decimal with a stated precision, never a float, and never a string with a currency symbol in it. A timestamp is an instant in UTC with an explicit format. A currency is a three-letter ISO code from a stated list. An availability status is one of an enumerated set of values, with each value defined. An identifier is a string, even if it looks numeric, because sites change identifier formats and leading zeros disappear when someone casts to an integer.

Units belong in the contract, not in the analyst’s head. For prices: which currency, whether tax is included, whether shipping is included, and whether the value is per item, per pack or per unit of measure. For dimensions and weights: which units, and whether they’re normalised or as displayed. For ratings: the scale, and whether it’s the site’s own scale or rescaled to a standard one.

Constraints catch obvious errors early and double as documentation. A price must be greater than zero. A rating must fall within the stated scale. A currency must be in the allowed list. A URL must be absolute. These are the same rules the validation guide describes for the collector’s own checks, and the contract is where they’re published so consumers know what’s already been enforced.

Put the machine-checkable part in a format tools can read: JSON Schema, an Avro or Protobuf definition, or a warehouse table definition with constraints. Keep it in version control next to the collector, and generate the human-readable field table from it, so the two can’t drift apart.

Include a field for the record’s provenance on every row: source site, fetch time, parser version. Consumers will need it the first time they question a value, and adding it later means a schema change.

What each value actually means

This is the section teams skip, and it’s the one that prevents the incidents that hurt.

For every field whose meaning isn’t obvious from its type, write one or two sentences defining it in terms of what’s on the page. For price: “the price a customer pays for one unit of the default variant, as displayed on the product page, including any active sale, excluding member-only prices, including tax where the site displays tax-inclusive prices.” That sentence is what would have stopped the opening story. When the extractor was fixed, someone would have noticed that the old behaviour didn’t match the definition, and the fix would have gone out with a notice.

Define the grain of the dataset. Is each row an observation, one fetch of one product at one moment, or a state, the current known values for one product? Is it one row per product, per variant, per seller, or per product per region? Grain mismatches cause more wrong aggregations than any other contract gap. An analyst who assumes one row per product and sums prices over a dataset that’s actually one row per variant gets nonsense.

Define identity. What is a product, for this dataset? Is a colour variant a separate product? If a site relists the same item under a new URL, is it the same product or a new one? The dedup guide covers building canonical keys; the contract says what those keys mean to consumers and how stable they are.

Define the special values. What does an availability of “unknown” mean, compared with “out of stock”? Is a rating of zero a real zero-star average or a product with no ratings?

Write definitions in terms of what’s observable on the page. “The sale price” is ambiguous. “The price shown in the main price element, which on sale items is the discounted price” is testable.

Null rules

Empty values are where scraped data is most ambiguous, and where consumers make the most costly assumptions.

A value can be absent for several different reasons. The page genuinely doesn’t have it: a product with no reviews has no rating. The extractor failed to find it: the selector broke. The field doesn’t apply: a digital product has no weight. The value was withheld: a price shown only after login. The collector didn’t look: the field was added to the schema after this page was fetched. All of these arrive as null unless the contract says otherwise, and they mean very different things to an analyst.

The contract should say, per field, which of these can happen and how each is represented. A common pattern is a nullable value plus a companion status or a per-record list of failed fields. So rating is null with rating_status set to none_on_page for a product with no reviews, and null with the field listed in extraction_failures when the extractor broke. The dead-letter guide in this series covers routing extraction failures; this is the representation consumers see.

Be explicit about the difference between null and an empty string, an empty array, or zero. A contract that says “string fields are never empty strings; absent values are null” saves every consumer from writing a check for both. A contract that says “a price of zero is never valid and never emitted” means a consumer seeing one knows it’s a bug.

Required fields deserve a clear rule. If price is required, a record without a price is never published. It goes to the failure path instead. That’s a promise consumers can rely on. If a field is required only sometimes, such as price required for in-stock items but optional for discontinued ones, say so.

And say what happens with fields that didn’t exist when older records were collected. Consumers querying history need to know that a field added in March is null for everything before March, and why.

How fresh, how wide, how complete

Consumers care about when data arrives and how much of it there is as much as what’s in each row.

Freshness is how recent the data is. State it as a commitment consumers can check: for example, “each active product is observed at least once per calendar day, and the day’s data is complete in the warehouse by 08:00 UTC the following morning.” Pick a threshold you can actually meet on a bad day, not the one you hit on a good day. Then publish the actual freshness alongside the commitment, so consumers can see when it’s slipping.

Coverage is what’s in scope: which sites, which regions, which categories, which page types. Coverage changes are among the most disruptive changes a collector can make, because they look like changes in the world. Dropping a region from collection makes a market-share analysis show that region shrinking. The contract lists the scope and treats changes to it as announced changes.

Completeness is how much of the in-scope universe each run actually captures. No collector captures everything every time. Pages fail, sites block, listings move. The knowing-whether-you-got-everything guide covers measuring this. The contract states the expected level, the metric used to measure it, and what happens when a run falls short: whether the run is still published with a flag, held back, or backfilled later.

Late data needs a rule. If a site was unreachable overnight and its data arrives a day late, does it land in yesterday’s partition or today’s? Does it overwrite anything? Consumers building daily aggregates need to know whether yesterday’s numbers can change after they’ve read them.

Publish these as metrics, not just promises. A small table per run with freshness, coverage and completeness per source lets consumers check the contract without asking you.

Identity and stability guarantees

Much of what consumers build depends on joining your data across time: tracking a product’s price history, counting how many products a seller lists each month, measuring how often items go out of stock. All of that relies on identifiers that stay stable.

The contract should say what the primary key is, whether it’s unique, and how stable it is. For example: “product_key is unique per product per source, derived from the source’s own product identifier, and stable as long as the source doesn’t change that identifier.” That last clause is the honest part. Sites do change identifiers, during platform migrations or catalogue restructures, and when they do, every product appears to be discontinued and replaced by a new one.

Say what the collector will do when that happens. The realistic commitment is detection and notice, plus a best-effort mapping where one can be built from URLs, SKUs, titles or other stable attributes. It’s rarely possible to promise a perfect mapping, and a contract that implies one sets up a failure.

State the uniqueness guarantee precisely. “At most one row per product_key per fetch” is different from “at most one row per product_key per day.” The dedup guide covers the mechanics. The contract tells consumers which guarantee they can build on.

If the dataset merges more than one source, say how merged identities work. Is a product listed on two sites one entity or two? If one, what’s the matching rule, and what happens when it’s wrong?

And say whether keys are ever reused. A site that recycles product IDs for new items after old ones are removed creates a history where one key describes two different products. If you can’t prevent it, flag it, and tell consumers to watch for discontinuities.

Change notice

The heart of a contract is how changes are handled. It helps to sort changes into kinds, because each deserves a different process.

Additive changes add something without affecting what exists: a new optional field, a new source, a new enum value in a field whose consumers were told to handle unknown values. These need notice but not coordination. A changelog entry and a message to consumers is enough. Consumers who don’t need the new field can ignore it.

Breaking changes alter or remove something consumers depend on: renaming or removing a field, changing a type, making an optional field required, changing the grain. These need a notice period and a migration path. The standard approach is versioning: publish the new shape as a new version alongside the old one, run both in parallel for an agreed period, and retire the old one after consumers confirm they’ve moved. The versioning guide covers how the collector tracks this internally.

Semantic changes keep the shape and change the meaning, like the price fix in the opening story. They’re the most dangerous kind because nothing breaks technically. The contract should treat them like breaking changes, with notice and, where possible, a flag or version marker on affected records so consumers can separate the old meaning from the new one. A fix that corrects wrong data is still a semantic change to anyone who built on the wrong data.

Coverage changes, adding or removing sources, regions or categories, sit between additive and breaking. Adding is usually additive. Removing breaks anything that counts or compares across the full scope.

Agree notice periods up front. They don’t need to be long, but they need to exist, and the contract should name the channel where notices go.

Changes you can’t give notice for

The awkward truth of scraped data is that many changes start at the target site, overnight, with no notice to you. A contract for scraped data has to handle those honestly.

The commitment you can make is about response, not prevention. For example: “When a source site change affects any contracted field, we’ll notify consumers within one working day of detection, flag affected records, and state whether and when affected data will be backfilled.” That’s achievable, and it’s what consumers actually need. They can’t stop the site changing either. What they need is to know which data to distrust and for how long.

Flagging is the key mechanism. Records collected during a known problem period should carry a quality flag, so consumers can exclude or annotate them without guessing at dates. The failure-handling machinery described in the dead-letter guide makes this possible: fingerprints tell you exactly which sources, fields and time windows were affected.

Backfill policy belongs in the contract too. When a problem is fixed, will the affected period be restated, meaning reprocessed from stored raw pages and republished? If so, consumers need to know that historical numbers can change, how they’ll be told, and how restated records are marked. If raw pages aren’t stored, the honest answer may be that the gap can’t be filled, and the contract should say that rather than imply otherwise.

Some upstream changes end a source entirely. A site starts blocking automated access, adds a login wall, changes its terms, or shuts down. The contract should say what consumers can expect then: notice as soon as it’s known, and no promise that an alternative will be found. Over-promising here is the fastest way to lose a consumer’s trust.

Enforcing it in code

A contract only in a document drifts from what the pipeline actually does. Enforcing it in code keeps both honest.

Start with the schema file as the single source of truth. The collector validates every output record against it before publishing, which is the same validation layer described in the validation guide, now tied to the published contract rather than to internal rules alone. A record that fails doesn’t get published. It goes to the failure path with the rule it violated.

Add contract tests to CI. On every change to the collector, run the extractors against the saved-page test suite and validate the output against the contract schema. A change that renames a field, changes a type, or starts emitting empty strings where the contract says null fails the build before it reaches consumers. This catches the accidental breaking change, which is the most common kind.

Semantic checks can be automated partially. Distribution checks per field per source, such as the median price, the share of in-stock items, and the fill rate, compared against recent runs, catch many semantic shifts. A fix that moves one retailer’s median price sharply overnight should trigger a review before publication, not after. This is the same machinery as silent-failure monitoring, pointed at the contract.

Run freshness, coverage and completeness checks per run and publish the results. If a run falls below the contract’s thresholds, the contract says what happens, whether that’s holding it back, publishing it with a flag, or alerting, and the pipeline does that automatically.

Encourage consumers to run their own checks on what they rely on. A consumer-side test that asserts the fields and properties they depend on is a cheap early warning and a clear statement of what matters to them.

One field, written out in full

Abstract advice about contracts is easy to agree with and hard to apply, so here’s what a single field entry looks like when it’s done properly. The schema file holds the machine-checkable part, and the human part sits beside it in the same file so they’re reviewed together.

- name: price
  type: decimal(12,2)
  required: true
  constraints: { gt: 0 }
  unit: currency given by the currency field
  tax: included where the site displays tax-inclusive prices
  meaning: >
    Price a customer pays for one unit of the default variant,
    as shown in the main price element on the product page,
    including any active sale, excluding member-only prices.
  null_rule: never null; records without a price are not published
  since: v1
  changed: v3 (sale price replaced list price on discounted items)

A few details in there do most of the work. The meaning is written in terms of what’s visible on the page, so a reviewer can open a product and check it. The null_rule makes the required promise explicit instead of leaving consumers to infer it from required: true. And the changed line records the semantic change from the opening story in the place consumers will look first, with the version it happened in.

The entry is also where disagreements surface. When a consumer reads “excluding member-only prices” and says their use case needs member prices, that’s a request for a new field, not a change to this one. Adding member_price as a separate optional field keeps both consumers’ assumptions true.

Not every field needs this much. An identifier or a URL can get by on name, type and a one-line meaning. The fields worth writing out fully are the ones where the page shows more than one plausible value, which on commercial sites usually means prices, availability, ratings and anything with units.

Ownership and the conversation around it

A contract needs an owner on each side, or it becomes a document nobody updates.

The producer owner is responsible for keeping the contract accurate, approving changes, and sending notices. In a small team, it’s the person who runs the collector. In a larger one, it’s whoever owns the dataset as a product. Name them in the contract.

Consumer owners are the people who get notified and who confirm migrations. List the known consumers and their contacts. That list is also valuable in its own right: it tells the producer who will be affected by a change, which is the first thing anyone wants to know before making one.

Keep a changelog with the contract, with every change, its date, its type, and what consumers need to do. The changelog becomes the history consumers check when a number looks odd. “Did anything change on the 14th?” should be answered by reading it, not by asking around.

Review the contract periodically, not only when something breaks. Consumers’ needs change. Fields nobody uses can be deprecated. Freshness commitments that were set conservatively can be tightened once the collector has proved it can meet them. A short review every quarter is usually enough.

And have the conversation before the contract, not instead of it. The first version should come out of talking to the people using the data about what they assume and what they need. The document records the agreement. It can’t create one on its own.

A starting template and what to do on Monday

If your collector has consumers and no contract, here’s the order we’d write one in.

List the consumers and ask each what they rely on. You’ll find assumptions you didn’t know about, and at least one that’s already wrong.

Write the field table from the existing schema: name, type, required, constraints, units. Add a one- or two-sentence definition for every field whose meaning isn’t obvious, written in terms of what’s on the page. Define the grain and the primary key.

Write the null rules per field, and add a status field or a per-record failure list if you don’t have one, so consumers can distinguish “not on page” from “extraction failed.”

State freshness, coverage and completeness commitments you can meet on a bad day, and start publishing the actual numbers per run.

Write the change process: the kinds of change, the notice for each, the channel, and the parallel-running period for breaking changes. Add the response commitment for upstream changes you can’t prevent, including flagging and backfill policy.

Name the owners, start the changelog, and put the schema file in version control with contract tests in CI.

Then send it to the consumers and ask what’s missing. The first round of replies will be the most useful feedback on your dataset you’ve had.

For more on the pipeline behind a contract like this, from validation and versioning to detecting changes on the sites themselves, the full set of guides is at Data Research Tools.

Get new guides and videos first — join the Telegram channel.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *