Prompt Engineering & Structured Output
Domain map for D4, worth 20% of the scored exam. Covers how to write prompts that steer Claude reliably, how to structure long and complex inputs, and how to guarantee machine-parseable output — plus the batch/review patterns that make extraction pipelines production-grade. Scenarios that lean on this domain: Structured Data Extraction and Claude Code for CI.
Concepts
- Prompt Clarity And Motivation — be specific + add the "why"; "show it to a colleague" test.
- Role Prompting — a one-sentence role in the **system** prompt shifts tone/behavior.
- XML Structuring — tag distinct content types; nest documents; use tags as format indicators.
- Few-Shot Prompting — 3–5 relevant/diverse examples in `<example>` tags; fix inconsistency with examples, not prose.
- Long-Context Ordering — documents first, query last (**up to 30%** quality gain) for 20k+ tokens.
- Prefill Migration — last-turn prefill returns **400 on 4.6+**; migrate to structured outputs / tool enums.
- Structured Outputs — `output_config.format`={type:'json_schema'}; **`additionalProperties:false` required**; constrained decoding = always-valid JSON.
- Validation-Retry Loops — generate → validate → retry (2–3 attempts); syntax vs semantic; fail fast on missing info.
- Message Batches API — 50% off, 100k/256MB, 24h, `custom_id ^[a-zA-Z0-9_-]{1,64}$`, 1h-TTL cache.
- Multi-Pass And Multi-Instance Review — same-prompt-N× vs sequential sharpening passes.
- Opus Severity-Filter Trap — "only report high-severity" tanks recall; report all, filter separately.
- Building Evals — code/model/human grading + Claude-as-judge rubric; eval-driven iteration.
- Prompt Technique Taxonomy — the anthropics/courses technique ladder (clear/direct → roles → few-shot → CoT → complex prompts).
- Mathematical consistency enforcement
- Resilient schema design
- Routing for cost and SLA