Claude and the Anthropic SDK · Chapter 21 of 21

Interview round

By the end of this chapter you have answered six timed questions, one idea each, from across the whole lab: reading any reply safely, a cache that never hits, JSON without forcing, what a photo costs, batch or real time, and retries that multiply. Each one ends with a measured run against the lab's Claude. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Ship it
  • 6 tasks
  • Python
  • In the all labs plan

The first 2 chapters of Claude and the Anthropic SDK are free. This one comes with the all labs plan.

Why you need this

Sahay is live. Families get answers on WhatsApp, Kamla's desk reads the first draft of every claim, and Farhan watches the bill. Meher wants a second engineer for Sahay, and Arjun runs the interview the way he reviews code: "Short problems, ten minutes each. I do not care whether you remember a field name. I care whether you know the edge that breaks a Claude app in production, and whether you measure instead of guessing."

Every question is a bug Parchi really had, or nearly had: a family whose answer crashed with an AttributeError, a cache that wrote on every request, a triage script that stopped working on a new model, a photo from a new phone, a batch nobody should have waited for, and an outage that sent twelve requests for one question. Each uses one idea from an earlier chapter, with no hand-holding: the file has the goal, the check has the edge cases, and every question is tried on requests the check makes itself. The ideas are below, as a refresher and as the things an interviewer listens for. The answers are not.

What you build: 6 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1 · interview question

    Interview: read_any_reply.py, why content[0].text fails

    Time yourself: 10 minutes. Write read_reply(reply) returning a dictionary {"text", "tools", "thought", "complete"}: the text blocks' text joined, the tool_use blocks' names in order, whether a thinking (or redacted_thinking) block is there, and whether stop_reason is end_turn. Never read content[0].

    Under if __name__ == "__main__":, ask "claude-opus-5-5" (max_tokens 4096, Sahay's system prompt, tools=TOOLS) How much will CLM-2402 pay? and print json.dumps(read_reply(reply)). The check reads replies with tools, citations, a cut and none of those.

  2. Task 2 · interview question

    Interview: stable_prefix.py, what invalidates a cache

    Time yourself: 10 minutes. old_request (given) writes the cache on every request and never reads it. Write build_request(question, now) returning the same request's arguments (model, max_tokens, the policy cached, the three tools, the question) with everything before the breakpoint the same byte for byte every time, and today(now) (given) still sent, after the cached part.

    Under if __name__ == "__main__":, send the three QUESTIONS (given) a day apart with old_request, then with build_request, and print old: read R1, R2, R3 and new: read R1, R2, R3 (the cache reads). The check sends four questions at four times through your build_request: every one after the first must read the cache.

  3. Task 3 · interview question

    Interview: triage.py, JSON without forcing

    Time yourself: 10 minutes. Write a pydantic model Triage (claim_id: str | None, category: Category, given) and triage(text) -> Triage: one client.messages.parse request to "claude-haiku-5-5" (max_tokens 1024, a system prompt of your own, the text as the one user message, output_format=Triage), returning parsed_output. No tool_choice, no prefill.

    Under if __name__ == "__main__":, send old_triage (given), catch the anthropic.BadRequestError and print old: STATUS TYPE; then print triage(text).model_dump_json() for Is CLM-2411 approved or still pending? and for Do you need a cancelled cheque for the claim?. The check triages inbox messages it never showed you.

  4. Task 4 · interview question

    Interview: before_upload.py, tokens from an image

    Time yourself: 10 minutes. Write preflight(data) returning {"ok": False, "reason": ...} for more than 5 MB or a side over 8000 px (size(data) is given); else {"ok": True, "tokens": N} where N is width x height / 750 rounded up, after scaling a long edge over 1568 px down to 1568 (both sides scaled and rounded).

    Under if __name__ == "__main__":, print FILE: N tokens for bill-CLM-2408.png and pharmacy-slip-ramesh.jpg. The check compares your answers with the API's own count for photos it makes up, two of which the API refuses.

  5. Task 5 · interview question

    Interview: batch_or_now.py, batch versus real time

    Time yourself: 10 minutes. Write run_day(jobs) -> dict[str, str]: every job with "claude-haiku-5-5", max_tokens 1024, system=SORT and its text. Waiting jobs go in real time, one messages.create each; the rest in ONE batch (custom_id the job's id), waited for and matched by custom_id. Return job id -> label ("unknown" for a result that did not succeed).

    Under if __name__ == "__main__":, run JOBS (given) and print ID (now): LABEL or ID (batch): LABEL for each job in order. The check runs jobs of its own.

  6. Task 6 · interview question

    Interview: retries_multiply.py, which errors to retry, and how often

    Time yourself: 10 minutes. Write requests_per_call(sdk_max_retries, wrapper_tries): the most requests one call can send when the SDK's retries sit under a wrapper's tries.

    Under if __name__ == "__main__":, for anthropic.Anthropic() and then anthropic.Anthropic(max_retries=0): lab_outage(40), one with_retries (given) call that fails, the requests the lab saw meanwhile (lab_request_count, given), then lab_clear_faults(). Print default client: N requests (formula F) and max_retries 0: N requests (formula F), with F from requests_per_call(2, 4) and (0, 4).

What you will learn

  • How to work a timed question: say the plan, name the edge, build the smallest thing that runs, then measure it.
  • Six ideas again, at interview depth: content blocks (chapter 1), the cache's prefix (13 and 14), structured output instead of a forced tool or a prefill (2, 7 and 9), image tokens and limits (10), batches (17), and retries (18).

More in Ship it

Build "Interview round" yourself

Parchi, a Jaipur startup, helps families claim health insurance. You build Sahay, a claims assistant that reads bills and policies with Claude, and measure what caching, models and effort cost. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Claude and the Anthropic SDK are free. This one comes with the all labs plan.