grok14ENGINEERING FIELD SCHOOL
Build / Week 2

Production Python & APIs

Build small services with explicit contracts, predictable failures, and tests that reveal real defects.

5 lesson sections16-hour study & practice planModule 01 or equivalent experience

See the system

Build small services with explicit contracts, predictable failures, and tests that reveal real defects.

The application boundary owns identity, authorization, action state, and budgets. Data retrieval supplies authorized evidence. Model generation proposes answers/actions. Trusted integration code enforces approval and records writes. Arrows show logical responsibility, not a cloud network specification.
Governed support copilot: logical architecture. The application boundary owns identity, authorization, action state, and budgets. Data retrieval supplies authorized evidence. Model generation proposes answers/actions. Trusted integration code enforces approval and records writes. Arrows show logical responsibility, not a cloud network specification.
Module 02 / Lesson 01

Separate transport from business logic

Keep request parsing, business decisions, and external integrations in separate modules. Your HTTP handler should validate input and call an application function. A model adapter should hide provider details behind a small contract so a fake can exercise failure paths in ordinary tests.

This separation makes changes cheaper: a provider SDK upgrade should not rewrite the approval policy. Prefer a small, well-defined interface to an elaborate abstraction that supports hypothetical future systems.

Apply the ideaSketch modules for API input, retrieval, model access, permissions, and persistence.
Module 02 / Lesson 02

Validate at every trust boundary

A type annotation helps readers and tools; it does not automatically validate an HTTP request at runtime. Check field types, maximum sizes, required identifiers, and allowed values. Reject unexpected state transitions on the server, even if the user interface disables the corresponding button.

Treat model output as untrusted input too. Parse a structured response, validate its schema, and apply domain rules before displaying or acting on it. Return stable error categories rather than leaking internal exceptions.

Apply the ideaDefine a ticket-update request and three malformed requests that must fail.
Module 02 / Lesson 03

Make failure behavior intentional

Every remote call needs a timeout. Retry only when the failure is transient and repeating the operation is safe. A read may be retried; a payment or ticket write needs an idempotency contract. Use bounded exponential backoff and account for the overall user-request deadline.

Concurrency improves I/O throughput but can overload a provider or exhaust connections. Bound it, propagate cancellation where supported, and distinguish a slow response from a permanently invalid request.

Apply the ideaWrite a table of timeout, rate-limit, validation, and authorization errors with the correct retry policy.
Module 02 / Lesson 04

Test behaviors and boundaries

Unit tests cover isolated rules. Contract tests verify an adapter’s request and response assumptions. Integration tests exercise real component boundaries. End-to-end tests check a critical user journey. Each has different cost and diagnostic value.

A test that simply repeats the implementation is weak. Use realistic counterexamples: empty input, a forbidden document, duplicate requests, a timeout, and a changed response schema. Keep ordinary tests deterministic with controlled fixtures.

Apply the ideaTest one success path and at least four independent failure paths in the supplied local reference lab.
Module 02 / Lesson 05

Make the service observable and reproducible

Use structured events with request IDs, stage names, durations, and stable error codes. Avoid logging raw prompts or customer records by default. Store configuration outside code and fail clearly when required settings are missing.

Pin the tested dependency environment, document the interpreter version, and give a clean setup command. A colleague should be able to reproduce a failure without guessing which package versions or hidden files you used.

Apply the ideaWrite a README containing setup, test commands, environment variables, and expected failure responses.

Worked scenario

A document API initially catches every exception and returns an empty answer. Users cannot distinguish “no evidence” from “provider unavailable.” Replace this with separate no-evidence, invalid-request, forbidden, and upstream-unavailable outcomes. Test that internal stack traces never become API responses.

A small example

This example isolates one concept. Read its boundary conditions before adapting it to an application.

python
from dataclasses import dataclass

@dataclass(frozen=True)
class Question:
    text: str

    def __post_init__(self):
        if not isinstance(self.text, str):
            raise TypeError("text must be a string")
        if not 1 <= len(self.text.strip()) <= 2000:
            raise ValueError("question length must be 1..2000")

print(Question("Where is the leave policy?"))

Practical assignment

Use the downloadable local reference lab where indicated. It uses synthetic data and Python’s standard library. The managed Databricks extension requires separate workspace verification.
  1. Run the reference lab tests.
  2. Trace the public function through retrieval and response assembly.
  3. Add a maximum question length validation.
  4. Add an invalid-input test and a timeout-adapter design.
  5. Document error categories and retry rules.
  6. Review logs for sensitive data before submission.

What to submit

Submit the artifacts named above, a short explanation of your decisions, and evidence of the checks you performed. Distinguish measured results from estimates and designs from executed integrations.

Review dimensionSubmission evidence
CorrectnessShow the expected behavior and a meaningful counterexample.
ReproducibilityState setup, inputs, versions, and what was actually executed.
Delivery judgmentExplain the client impact, alternative, and unresolved assumption.
Operational boundaryIdentify permissions, failure behavior, and any resource cleanup.

Knowledge check

1. Which operation is automatically safe to retry?
2. Do Python type hints validate incoming JSON automatically?
3. What belongs in ordinary diagnostic logs?

Answer guide
  1. Only an operation whose retry semantics are established. A network failure may occur after a write committed. An idempotency strategy is needed for safe repetition.
  2. No. Runtime validation must be implemented or supplied by a validation framework.
  3. Request ID, duration, stage, and safe error code. Operational metadata supports diagnosis without unnecessarily copying sensitive content.

References & next step

Platform examples are environment-dependent. Start with the official documentation in the reference library and verify the exact cloud, region, privileges, and versions you use.

Open the official reference library

Editorial edition: 5 October 2026. The local reference lab is executed locally; this course does not claim a live Databricks deployment.