Primary domains: D4 Prompt Engineering & Structured Output (20%) · D5 Context Management & Reliability (15%) — spans 35%
One of only two routes into D4 (with s5.md). The least glamorous lab, and joint-cheapest route into a 20% domain — do not skip it because the agent scenarios are more interesting.
Brief
A structured data extraction system built with Claude. It extracts information from unstructured documents, validates the output against JSON schemas, and maintains high accuracy. It must handle edge cases gracefully and integrate with downstream systems.
Task statements in play
| ID | Statement |
|---|---|
| 4.1 | Design prompts with explicit criteria to improve precision and reduce false positives |
| 4.2 | Apply few-shot prompting to improve output consistency and quality |
| 4.3 | Enforce structured output using tool use and JSON schemas |
| 4.4 | Implement validation, retry, and feedback loops for extraction quality |
| 4.5 | Design efficient batch processing strategies |
| 5.5 | Design human review workflows and confidence calibration |
| 5.6 | Preserve information provenance and handle uncertainty in multi-source synthesis |
The decisions it tests
Enforce structure, don't request it. Task statement 4.3 says it plainly: structured output is enforced through tool use and JSON schemas, not by asking politely for JSON in the prompt. A schema the model must satisfy is a constraint; "respond in valid JSON" is a hope.
Validation, retry, and feedback loops. Schema validation failure is a signal to feed back and retry, not an exception to swallow. Defensive parsing on the way out, because a confidently malformed response is the normal failure — not a rare one.
Never trust stated confidence. The published sample items across these guides hammer this: a model citing a specific-looking subsection number can be fabricating it, and self-reported confidence is not an accuracy signal. Validate factual claims against the source. This is the whole point of task statement 5.5, confidence calibration — and it pairs with routing low-confidence extractions to human review rather than accepting them.
Batching is a design choice. The Message Batches API: 50% cost savings, up to 24-hour processing window, no guaranteed latency SLA. Appropriate for non-blocking, latency-tolerant workloads (overnight reports, weekly audits, nightly test generation) and inappropriate for blocking workflows (pre-merge checks). It does not support multi-turn tool calling within a single request, and custom_id correlates request/response pairs — which is also how you resubmit only the failed documents. Parallel synchronous requests get you none of the cost saving.
Provenance under uncertainty. When merging extractions from several documents, keep field-level attribution — which document and page each value came from — and represent uncertainty explicitly rather than silently picking a winner.
Reference build
- A schema-enforced extractor using tool use, not prompt-requested JSON
- Three deliberately malformed documents — a missing field, a contradictory duplicate, an unparseable date — with the graceful degradation for each demonstrated, not described
- A validation → feedback → retry loop with a bounded retry count and a defined give-up path
- Confidence thresholds routing low-confidence records to a human review queue
- Field-level provenance in the output, so every value traces to a source and page
- A batch path for the high-volume case, with the cost rationale written down
Traps
- Hope over enforcement — "return valid JSON" in the prompt instead of a schema.
- Trust the model's confidence — accepting a self-rated confidence score as a quality gate, or sending a cited figure onward without verifying it against the source.
- Swallowing validation failures instead of feeding them back.
- Unbounded retries with no give-up path.
- Parallel synchronous calls for an overnight batch job, where Batches is the answer.
- Dropping provenance during multi-document merge.