Lab 07 — A data-quality gate

Scaffold: 2/5. The pipeline reads, routes, and reports. You write the rules that decide what is fit to feed a model.

The scenario

Before documents reach a knowledge base, something has to stop the bad ones. Raw support-ticket records land in s3://BUCKET/incoming/: most are fine, some have an empty body, a nonsense priority, a missing email, or are not even valid JSON. Ingesting those poisons retrieval. A gate reads each record, decides, and routes it: good records to clean/, bad ones to quarantine/ with the reasons attached. This is the hand-built version of AWS Glue Data Quality, so the idea of a declarative gate is concrete.

The requirement

Run the gate and every record ends up in the right place: the three good tickets in clean/, and the three broken ones in quarantine/, each with a note of what failed. Only clean/ would go on to ingestion.

What’s provided

Your task

Implement validate(record) in src/handler.py, returning (ok, reasons):

A record that breaks any rule goes to quarantine with the reasons; a clean one passes. (The malformed-JSON record is caught for you before validate runs.)

Run it

./scripts/deploy.sh
./scripts/test.sh
./scripts/teardown.sh

What success looks like

test.sh prints {"clean": 3, "quarantined": 3}, lists three objects under clean/ and three under quarantine/, and shows T-5’s reasons (bad priority, missing email). Before you fill validate(), the function raises NotImplementedError.

If it fails

Reveal the solution

SRC=solution ./scripts/deploy.sh && ./scripts/test.sh

What you just learned

Next

Lab 08 — Answer a metric question with text-to-SQL. You move from documents to structured data: a question becomes a SQL query the model writes, run against a real table, with the guardrails that keep generated SQL safe.