Page 4 of 8~112 min topic

Batch API lab

Validate outputs and schemas

Executable checks prove each input line has a stable custom_id; failed lines never poison the whole file on fixtures — including the known misshape behind BATCH-DUP-8841.

~14 min this pageValidation

1Learn the idea

Read

Schema and policy checks

Add executable validation at the trust boundaries of overnight batch job that grades 50k support transcripts via provider Batch API. Reject unknown fields where they matter, bound string sizes, and coerce only after auth/signature checks when raw bytes are security-relevant. Invariant under test: each input line has a stable custom_id; failed lines never poison the whole file. A TypeScript type or Python annotation is not runtime validation — pair them with parsers.

Read

Golden and adversarial fixtures

Automate the fixtures from setup, including a recreation of BATCH-DUP-8841. Assert both the visible error and the absence of side effects (no provider call, no queue write, no flag flip). Where metrics matter, assert label enums stay bounded.

Read

Implementation artifact

def validate_output_line(line: dict) -> str | None:
    if "custom_id" not in line: return "missing_custom_id"
    if "error" in line and "response" in line: return "both_error_and_response"
    if "response" in line and line["response"].get("status_code") != 200: return "non_200"
    return None

Read

Gate semantics

Document which failures are client mistakes (4xx) versus operator/config mistakes (5xx/503). Oracle still stands: fixture of 20 lines yields 18 succeeded + 2 failed with error objects; cost ≤ $0.40. Validation should make accidental “success with empty body” impossible for QA lead who needs cost-capped offline eval by 07:00 UTC.

Read

Stage depth

Property ideas: shuffled field order, Unicode edges, maximum-length strings, and replayed timestamps. Where money, identity, or citations matter, assertion messages should cite the field name. Do not snapshot entire provider payloads in tests; assert semantically. If validation fails open “to keep the demo working,” you have inverted the lab. Tie at least one CI job to the BATCH-DUP-8841 fixture so main cannot regress silently. Re-read each input line has a stable custom_id; failed lines never poison the whole file after each new parser — convenience helpers love to bypass it.

Read

Field notes for `batch-api-lab` / `validation`

Table-drive status codes and error codes so reviewers see coverage at a glance. Include a Unicode normalization case if user text is accepted. Verify that oversized bodies fail before CPU-heavy work. Where digests or versions are pinned, assert mismatch behavior. Keep golden files small enough to read in review. CI should fail on skipped tests that mark the incident fixture as xfail without a ticket link. In this chapter the product is overnight batch job that grades 50k support transcripts via provider Batch API, the human stakeholder is QA lead who needs cost-capped offline eval by 07:00 UTC, and the incident id you design against is BATCH-DUP-8841. Re-state the oracle in your notes — fixture of 20 lines yields 18 succeeded + 2 failed with error objects; cost ≤ $0.40 — and keep the invariant visible: each input line has a stable custom_id; failed lines never poison the whole file. Track batch_line_success_ratio ≥ 0.90 and dollars_per_1k_lines ≤ 8 as the scoreboard. Surface under change control: POST /v1/batches. If you only have forty minutes, finish the fixture for duplicate custom_id causes silent overwrite of the better grade before polishing UI. Promotion language stays ternary: promote, hold, or roll back based on evidence, not hope.

Go deeper

Before you start

Why this matters

List three fixtures: one golden success, one schema/auth reject, and one regression for BATCH-DUP-8841. For each, write the exact assertion (status, code, metric, or citation) that must turn red if broken.

In the wild

See how this idea shows up as a product and a company — then come back to the lesson. Skills transfer across vendors.

Check your understanding

Page assessment

Answer from memory. Completion is saved from this evidence, not from opening the next page.

1. Do parsers run before side effects?
2. Is BATCH-DUP-8841 represented as a fixture?
3. Are side-effect absences asserted?

All responses are required.