Unit 12 of 12 · about 4 hours · measure
Locked-evaluation comparison of interface and context variants
A better-looking answer is not a controlled comparison. Locking cases and acceptance checks makes a context change attributable and prevents an aggregate gain from hiding a critical regression.
You'll be able to
- Compare one declared interface or context change on a frozen, versioned case set and scorer.
- Measure paired task outcomes, contract failures, token use and latency without hiding retries or incomplete cases.
- Explain whether the evidence supports keeping the variant, rejecting it or collecting more trials.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Compare on the task, not a leaderboardAI Engineering Handbook
The workflow: shortlist, test, decide; When to switch models (page read 2026-10-18)
Use the comparison structure, not the hosted candidate calls. Skip the sample substring scorer: it can pass an incorrect answer containing the gold text. Use validated structured values and an independent task oracle.
- Keep deterministic and behavioral gates separateAI Engineering Handbook
Two layers, two test strategies; Don't snapshot model responses: gate on a cohort (page read 2026-10-18)
Do not adopt the example cohort size or degradation tolerance as a universal statistical guarantee. Use per-case paired results and disclose limited local trials.
- A bounded context interventionAI Engineering Handbook
Where you put things matters as much as what you put; How this fails in production (page read 2026-10-18)
Choose one ordering, truncation or schema-boundary variant. Do not add retrieval, routing or agent frameworks to this comparison.
Focus on
- Freeze case IDs, source revisions, expected facts, scorer code and acceptance rules before testing. Keep development cases separate; changing a scorer after inspecting results creates a new evaluation version.
- Hold the model, tokenizer, template, controls and gateway policy fixed except for the declared intervention. For a provider or model swap, label the whole backend bundle as the intervention rather than claiming a prompt-only effect.
- Keep per-case paired outcomes and slice failures by cause: missing evidence, schema rejection, refusal, truncation and transport failure. Count every attempt and unknown usage; do not remove failed cases from the denominator.
- Measure end-to-end latency with a monotonic clock and token counts with the established accounting contract. Separate warm-up from measured runs and report hardware, versions and cache conditions. Fake-clock latency tests validate accounting, not real serving speed.
Common mistakes · 3
- Changing the model, examples, context budget and grader together, then attributing the result to message ordering.
- A substring match that passes a negated answer or an answer listing every possible value. Test the scorer against deliberate false positives and malformed outputs.
- Treating one small aggregate improvement as a reliable win. Show paired regressions and repeated local trials when feasible; preserve uncertainty and hard privacy or contract gates.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.The variant passes more easy cases but exposes another tenant's document. Can its average score justify release?Answer
No. Tenant isolation is a hard gate, not a quality score that can be averaged away. Reject or fix the variant.
2.Why retain a case where the model timed out?Answer
Timeout is part of the variant's observed behavior and resource cost. Dropping it biases the success rate and latency summary toward surviving requests.
3.Can deterministic fake outcomes establish that one ordering improves a real model's factual accuracy?Answer
No. They test the comparison machinery and declared contract behavior. Factual-quality claims require measured model trials on the fixed cases.
4.A grader bug is discovered after the run. What should happen?Answer
Version the corrected grader, preserve the original artifacts and rescore both variants consistently. If the cases or criteria were tuned to favor a variant, use a fresh locked set for confirmation.
You're done when
A reviewer can reproduce the comparison from safe manifests, identify the one intended change, inspect every failed case and distinguish measured results from fake-only checks or unsupported conclusions.
Only when you can do this without notes.
Leads to
Notes
Resources · 1 for this unit, 11 more in the section
- AI Engineering HandbookHandbook Academy · required
Study Part 2 Working with Model APIs and Part 5 Context Engineering (
/curriculum/context-engineering/): calling models, streaming, structured outputs, function tools, errors, retries, fallbacks, model choice, gateways, prompt caching, context assembly and compression. Skip the transformer overview owned by LLM Foundations.
Also in this section
- AI Agents in DepthBojie Li · primary
Read Chapter 1 sections 1.1 and 1.2.4 to 1.2.6 (agent, workflow, harness and guardrail distinctions), then Chapter 2: 2.2.1 to 2.2.5 (message roles and the tool loop), 2.3 KV-cache-friendly context design, 2.4 with 2.4.7 prompt injection, 2.6 and 2.7 (dynamic context and compression). Use the live English edition on the rendered site; the older PDF numbers some sections differently. The book does not cover streaming events, finish reasons or schema subsets, so take those from the provider contracts.
- Effective Context Engineering for AI AgentsAnthropic · required
Study context as a finite resource, just-in-time retrieval, compaction, note taking and context isolation. Convert the advice into explicit selection and truncation policies, then test where each policy loses decisive information.
- OpenAI API Contracts: Structured Outputs, Function Calling, Streaming and ErrorsOpenAI · required
Read Structured Outputs (
#supported-schemas,#refusals: root must be an object, every field required with a nullable union for optional values,additionalProperties: false), Function calling (#the-tool-calling-flow,#strict-mode,#streaming), the Chatfinish_reasonvalues and Responsesstatusandincomplete_details, the error codes and rate-limit headers, and prompt caching (#how-caching-works, the per-model table). Record fixtures from the documented shapes; no paid calls are needed. - Claude API Contracts: Messages, Stop Reasons, Tools, Streaming and ErrorsAnthropic · required
Read the stop-reason values (
end_turn,max_tokens,stop_sequence,tool_use,pause_turn,refusal,model_context_window_exceeded), Messages (top-levelsystem,tool_useandtool_resultblocks), tool definitions and forcing, structured-output schema limitations (optional properties allowed, no recursion), streaming event types (usage inmessage_deltais cumulative; an error event can follow HTTP 200), the error table (529 overloaded) and prompt-caching usage fields. Translate semantics in your adapter instead of forwarding JSON between providers. - Chat Templates and Token AccountingHugging Face; OpenAI · required
Read "Using apply_chat_template" and
add_generation_prompt, then the tools section of the chat extras page. Count the rendered request (roles, separators, system prompt, tool definitions, generation prefix) with the model's own tokenizer, selectinginput_idsfrom the returned encoding. Compare withtiktokenonly as an OpenAI-family reference; it is not a universal counter for local models. - Local OpenAI-Compatible Server: vLLM, llama.cpp or OllamavLLM; ggml-org; Ollama · support
Pick one local server. vLLM 0.31.0: structured outputs (
response_formatjson_schema; the oldguided_*fields were removed in 0.12.0) and tool calling (Qwen uses--tool-call-parser hermeswith--enable-auto-tool-choice). On CPU use llama.cppllama-server(--json-schema, grammars) or Ollama (formatwith a JSON schema). Pin the server version and model revision, and test the exact wire shapes your adapter accepts. - Pydantic Strict Mode, Extra Data and Discriminated UnionsPydantic · support
Read strict mode,
ConfigDict(extra="forbid"), discriminated unions and JSON Schema generation. A generated schema leaves defaulted fields out ofrequiredand emits a rootoneOffor a union, so it is not an OpenAI strict schema as is: adapt the wire schema explicitly and keep the model as the final validator. Never pass untrusted tool arguments throughmodel_construct. - Timeouts, Retries, and Backoff with JitterAmazon Builders' Library · support
Read "Timeouts", "Retries and backoff" and "Jitter". A timeout does not mean the work did not happen; retry at one layer only. The five-layer example uses three tries per layer, so the amplification is
3**5 = 243; state attempts and retries explicitly in your own budget. - AlgoMaster AI EngineeringAlgoMaster · support
Read the free lessons
making-your-first-llm-api-call(the error table and the retry wrapper that skips permanent errors),understanding-llm-parameters,structured-output-from-llmsandtype-hints-and-pydantic; the owned premium lessonsstreaming-and-conversation-management,context-engineeringandthe-ai-gateway-patternextend them. The course calls a hosted router: point the clientbase_urland model at your local server instead, and keep this stage's stricter versioning, replay and fault checks. - The Hitchhiker's Guide to Agentic AIHaggai Roitman · support
Use v3 Chapter 18: 18.2 context management (18.2.6 token counting and budget monitoring), 18.3 prompt architecture, 18.4.1 (the OpenAI and Anthropic tool schemas side by side), 18.4.3 error normalization and retry, 18.7.1 backoff with jitter. It is a breadth audit of the gateway after it works, not a contract reference.
- JSON Schema LearnJSON Schema Project · reference
Read the object reference sections on
additionalProperties,requiredand extending closed schemas (unevaluatedProperties), and Validation 6.5.3 in the 2020-12 specification:propertiesdoes not require keys,requireddoes not forbid null, and closing one subschema does not close a composed one. Check payloads withjsonschema(Draft202012Validator,iter_errors) and keep the full domain schema as the final validator even when a provider accepts only a subset.