Domain 4 · 20% of exam
Prompt Engineering & Structured Output flashcards
103 cards distilled from the six task statements in this domain, one question per fact the exam can actually ask for. Anything you mark “Again” comes back at the end of the round, and again tomorrow — a card you keep getting right moves up a box and goes quiet for longer each time, up to a fortnight.
Use these once you have read the lessons — they test recall, not understanding. For the reasoning behind any answer, the domain curriculum explains it, and the cheat sheet condenses it.
Loading your deck…
Every card in this deck
The whole deck as a list, for scanning or printing.
- Where does the Messages API expect explicit review criteria to live?
- In the top-level `system` parameter. `role: "system"` entries in `messages` are mid-conversation system messages added partway through, not the standing system prompt.
- What happens to consecutive same-role messages in a request?
- They are combined into a single turn, not rejected.
- Is `max_tokens` a target or a ceiling?
- An absolute ceiling only — the model may stop generating before reaching it.
- Does lowering `temperature` fix a review prompt's false positives?
- No — temperature is a sampling setting, not a precision control: it changes run-to-run variation, not which findings the prompt defines as reportable. Write explicit report and skip criteria.
- What are the two prompt-design failure modes Anthropic names?
- (A) Hardcoded, brittle if/else-style logic — fragile and hard to maintain. (B) Vague, high-level guidance — no concrete signal (e.g. "be conservative").
- What is the "right altitude" target for a system prompt?
- The minimal set of information that fully outlines expected behaviour — not a laundry list of every edge case.
- How should categorical criteria (e.g. severity) be enforced structurally?
- As a tool `enum` field or via structured outputs — not left to prose interpretation.
- What eval-set size is enough to see the impact of a prompt change early on?
- About 20 representative queries.
- What is the documented "best form of feedback"?
- Clearly defined rules for an output, plus an explanation of which rules failed and why (e.g. code linting).
- What does a high false-positive rate in one review category do to trust in other categories?
- It destroys it — trust is not category-specific, it bleeds across the whole output.
- What is the correct fix for a category with an unacceptably high false-positive rate?
- Temporarily disable that category, refine its criteria with concrete code examples, then re-enable it.
- How should severity levels be defined for consistent classification?
- With concrete code examples per level, never prose descriptions alone.
- What three reasons make "only report high-confidence findings" fail?
- Self-reported confidence is poorly calibrated; it doesn't encode your policy (many false positives are high-confidence findings the team doesn't care about); and it is unauditable.
- Why must a skip list end with "omit it, do not report it at a lower severity"?
- Without it the model keeps out-of-scope findings by downgrading them to "low", so the skip list becomes a report-as-low list.
- What is shadow mode for a disabled review category?
- Generate and log its findings without posting them, to measure precision while its criteria are reworked; re-enable at a precision bar set in advance.
- Why measure review precision per category rather than overall?
- One noisy category drags the overall figure down and hides where the noise comes from; developers see the overall figure, not the 91% category.
- What is the first-choice fix when detailed instructions still produce inconsistent output formatting?
- Few-shot examples — not more instructions, not confidence thresholds, not temperature adjustments.
- How many few-shot examples should you typically use?
- 2-4 targeted examples on the exam (current Anthropic docs: 3–5). Fewer than 2 doesn't establish a pattern; 8-10 'for coverage' wastes tokens and dilutes attention.
- What must a good few-shot example include beyond input and output?
- Reasoning — why one action was chosen over plausible alternatives. This teaches generalisation, not just pattern-matching.
- How does Anthropic's context-engineering guidance describe good few-shot examples?
- "Pictures worth a thousand words" — curated, diverse, and canonical.
- What does Anthropic explicitly NOT recommend for handling edge cases?
- Stuffing a laundry list of edge cases into a prompt in an attempt to articulate every possible rule.
- For classification tasks, what should pair with few-shot examples to guarantee valid labels?
- A tool with an `enum` field listing valid labels, or structured outputs.
- Why can piling in 8-10 few-shot examples hurt output quality?
- "Context rot" — as token count grows, accuracy and recall degrade, diluting attention on the pattern that matters.
- Malformed JSON output in ~5% of responses — which technique fixes it?
- tool_use with JSON schemas, not few-shot examples (few-shot fixes consistency, not structural syntax).
- Few-shot examples fix inconsistent output. What is the multi-agent equivalent of leaving them out?
- Vague per-subagent task descriptions — no objective, output format, or boundaries — so subagents duplicate work and leave gaps. Same fix both times: show the expected shape explicitly instead of describing it.
- How should a few-shot example handle an informal measurement like "a couple of tablespoons"?
- `quantity` null, keep the original text, flag it informal — never convert it to an invented number.
- What is a few-shot contrast pair?
- An acceptable pattern and a similar-looking genuine issue shown side by side with reasoning, so the model learns where the boundary falls.
- Similar tools with minimal descriptions are being confused. First fix?
- Improve the tool descriptions; few-shot examples only for requests still ambiguous after that (sample question 2).
- An agent skips a required step (verify before refund) in 12% of cases. Few-shot examples?
- No — ordering is compliance, not judgement. Enforce it with a programmatic prerequisite or hook (sample question 1).
- Rank the structured-output reliability hierarchy.
- 1) tool_use with JSON schemas — eliminates JSON syntax errors entirely. 2) Prompt-based JSON — can produce malformed output.
- List the four tool_choice values and their defaults.
- `auto` (default with tools), `any` (must call a tool, model picks which), `tool` (forces a specific tool), `none` (default with no tools).
- Does tool_choice "any" alone guarantee the tool's input matches its schema?
- No — only that a tool is called. Add `strict: true` on the tool definition for the schema-validation guarantee too.
- What is the newer Structured Outputs feature, distinct from tool_use?
- Structured outputs: JSON outputs (`output_config.format`) constrain Claude's direct response via constrained decoding, no tool call; strict tool use (`strict: true`) constrains tool inputs. `output_format` is deprecated.
- What model availability applies to the Structured Outputs feature?
- Current docs: "Structured outputs are available on every model", and they are the documented replacement on models that reject forced tool use.
- What must `additionalProperties` be set to in a structured-output object schema?
- `false` — any other value is rejected.
- Name four things NOT supported in structured-output JSON schemas.
- Recursive schemas, external `$ref`, numerical constraints (minimum/maximum/multipleOf), string constraints (minLength/maxLength).
- What latency cost applies the first time you use a new structured-output schema?
- Extra latency while the grammar compiles; compiled grammars are then cached for 24 hours from last use.
- When can schema-constrained output still fail to match its schema?
- When `stop_reason` is `refusal` (the refusal takes precedence over the schema) or `max_tokens` (output may be incomplete). Check `stop_reason` before trusting the payload.
- What happens if you prefill the last assistant turn on Claude 4.6+ / Mythos Preview?
- The request returns a 400 error — prefill on the last turn is no longer supported on those models.
- What is documented as prefill's migration path for forcing output formats?
- The Structured Outputs feature — designed specifically to constrain responses to a given schema.
- What does tool_use with JSON schemas eliminate — and what does it NOT eliminate?
- Eliminates: JSON syntax errors. Does NOT eliminate: semantic errors — sum discrepancies, field placement, fabrication.
- How do you prevent a model from fabricating a value for a field the source document lacks?
- Make the field optional/nullable rather than required — a required field pressures fabrication; a nullable field allows an honest `null`.
- What schema pattern handles genuinely ambiguous and extensible categories?
- Add an "unclear" enum value for ambiguous cases, and "other" paired with a freeform detail string for extensible ones.
- What do current docs say about forced `tool_choice` (`any`/`tool`) on the newest models?
- On Fable 5.2, Mythos 5.2, Opus 5.5, Sonnet 5.5, Fable 5.1 and Mythos 5.1 it returns a 400; use `auto` + strict tool use, or structured outputs. Exam answer is still forced selection.
- How are `other` and `unclear` enum values routed differently?
- `other` (classified, outside the enum) → record the detail, extend the enum when a value recurs; `unclear` (cannot classify) → human review.
- How do you make `extract_metadata` run before enrichment tools?
- Force it by name on the first request, then switch back to `auto` for follow-up turns — `any` doesn't control which tool, and forcing every turn never ends.
- What three things must a retry-with-error-feedback message include?
- The original document, the failed extraction, and the specific validation error.
- Does the API automatically retry an invalid or incomplete tool call for you?
- No. Send a `tool_result` with `is_error: true`; Claude might call the tool again, so cap retries in your own loop. `strict: true` on the tool removes invalid calls entirely.
- What is the Messages API's general feedback-reporting contract for a failed tool execution?
- Return `content` plus `"is_error": true` in the `tool_result`, saying what went wrong and what to try next; Claude can then call the tool again or tell the user what happened.
- List error types retries CAN fix.
- Format mismatches, structural output errors, misplaced values, and mathematical errors (e.g. a missed line item).
- List error types retries CANNOT fix.
- Information genuinely absent from the source document, data that exists only in an external document, or knowledge the model lacks.
- What should you do with an unfixable extraction failure?
- Flag it for human review, or return null if the schema allows — do not keep retrying.
- What self-correction schema pattern flags total discrepancies automatically?
- Extract `calculated_total` (computed from the line items, never copied) and `stated_total` (as printed, nullable); flag when they differ.
- What does a `conflict_detected` boolean capture?
- That the source document contradicts itself (e.g. two different payment-terms statements). Pair it with a `conflict_note` saying what conflicts, rather than the model silently picking one.
- What does a `detected_pattern` field enable over time?
- Systematic analysis of which code construct or document feature triggers dismissed findings, prioritising prompt refinement.
- Fix for a pattern that fails repeatedly despite retries?
- Add a formal rule or refine the prompt/schema for that specific pattern — an architectural fix, not another retry.
- Distinguish schema syntax errors from semantic validation errors.
- Syntax errors (malformed JSON, wrong types) are eliminated by tool_use. Semantic errors (wrong sums, misplaced values) require validation logic and retry loops.
- What ranking does Anthropic give LLM-as-judge feedback vs rules-based feedback?
- Rules-based (clear rules + which failed and why) is best; LLM-as-judge is "generally not a very robust method" with heavy latency tradeoffs.
- After a `tool_use` whose input failed semantic validation, what goes back?
- A `tool_result` with `is_error: true` carrying the specific errors — tool_result first, any text after, same `tools` — not plain text in a new user turn.
- What stops a retry loop on a totals mismatch the document itself causes?
- `conflict_detected: true` with a `conflict_note`: accept as extracted and route to review instead of retrying.
- How should a loop decide whether an error is worth retrying?
- Before the first retry, from a typed `retryable` flag set by the check that raised it — not by matching words in the error text.
- Which `detected_pattern` should be fixed first?
- The one with the most dismissals (frequency × dismissal rate), not the highest dismissal rate.
- A developer dismisses a finding that is correct but unwanted. Fix?
- A criteria change (Task 4.1) — drop the category from what is reported; it is not a model error to tune away.
- Message Batches API cost discount?
- 50% of standard API prices, unconditionally.
- Typical vs maximum batch processing time?
- Most batches finish in under 1 hour; the hard maximum is 24 hours, with NO latency SLA guaranteed.
- Message Batch size limit?
- 100,000 requests OR 256 MB, whichever is reached first — exceeding size returns a 413 request_too_large error.
- custom_id format and purpose?
- Matches `^[a-zA-Z0-9_-]{1,64}$`; used to match results to requests because results can return out of order.
- Batch processing_status lifecycle?
- `in_progress` → (optionally `canceling`) → `ended`, once every request has a terminal result and results are ready.
- The four per-request batch result types?
- `succeeded`, `errored`, `canceled`, `expired`.
- Which batch result types are billed?
- Only `succeeded`. Errored, canceled, and expired requests are all NOT billed.
- Where and when are batch results available?
- A `.jsonl` file at `results_url`, populated only once the batch has `ended`; the docs recommend streaming rather than bulk-downloading.
- How long are batch results downloadable, and from when?
- 29 days, measured from `created_at` — NOT from `ended_at`.
- Which four request params are rejected in a batch with a validation error?
- `stream: true`, `speed` (fast mode), `fallbacks` and `max_tokens: 0`.
- When does batch param validation surface errors?
- Asynchronously — only after the entire batch has ended, not at submission time. Dry-run a single request against the synchronous API first.
- Recommended prompt-cache TTL for batch workloads?
- The 1-hour cache duration, since batches often take longer than the default 5-minute cache window.
- Do server tools (web search, code execution, etc.) work inside a batch?
- Yes — the batch worker runs the same server-side agentic loop as the synchronous Messages API.
- What genuinely cannot happen mid-batch, and what's the fix?
- Turn continuation — if a result comes back `pause_turn`, you must submit a NEW follow-up request (batch or synchronous); it cannot continue inside the original batch.
- Matching rule: synchronous vs batch API?
- Synchronous for blocking workflows (someone/something waiting, e.g. pre-merge checks). Batch for latency-tolerant workflows (overnight reports, weekly audits).
- A report has a 30-hour SLA and the Batch API window is up to 24 hours. When must the final batch go in?
- At least 24 hours (plus any downstream time) before the deadline. For a rolling 30-hour SLA, the gap between submissions + 24h + downstream must fit 30h: every 4h in the guide's example, 6h at most.
- Correct batch failure-handling pattern?
- Identify failures by custom_id, resubmit ONLY those with targeted modifications (chunking, simplified prompts, format-specific examples) — never resubmit the whole batch.
- Why refine prompts on a sample set before a large batch run?
- First-pass success rate compounds: 90% success on 1,000 docs = 100 retries; 60% success = 400 retries, 4x the resubmission cost.
- Can a 24-hour (or shorter) SLA be guaranteed on the Batch API?
- No — the 24-hour window is a ceiling on a single batch, so no submission frequency guarantees less. Use the synchronous API.
- What custom_id should a resubmitted or chunked request use?
- A derived id such as `doc-0042-retry-1` or `doc-0042-chunk-0`, so the run is distinguishable and the parent recoverable (leave room in the 64 characters).
- How should each batch failure type be resubmitted?
- Oversized → chunk under derived ids; `expired` or server error → resubmit unchanged; `canceled` → resubmit if still wanted; other invalid request → fix the body first.
- Why iterate the sample set on the synchronous API, not the batch API?
- Each batch round can take up to 24 hours, so three rounds can cost three days; the synchronous API gives feedback in seconds.
- Why does self-review in the same session underperform an independent instance?
- The model retains its original reasoning chain and tends to confirm rather than challenge its own prior decisions.
- Official documented reason a fresh session improves code review?
- "A fresh context improves code review since Claude won't be biased toward code it just wrote."
- Describe the Writer/Reviewer session pattern.
- Session A generates the artefact; a separate Session B reviews it fresh; Session A then addresses the feedback.
- What does a fresh adversarial reviewer subagent actually see?
- Only the diff and the review criteria — never the reasoning that produced the change.
- What distinguishes "verification by a second opinion" from a simple re-check?
- The fresh model actively tries to refute the result, so the agent that did the work isn't the one grading it.
- What architectural property underlies independent review instances?
- Subagent context isolation — subagents use their own isolated context windows and only send relevant information back.
- Three symptoms of attention dilution in single-pass multi-file review?
- Inconsistent depth across files, missed bugs in middle files, and contradictory findings across files.
- Correct fix for attention dilution?
- Split into per-file local analysis passes plus a separate cross-file integration pass — NOT a bigger context window.
- Why doesn't a larger context window fix attention dilution?
- The problem is attention quality, not context capacity — more room doesn't stop uneven attention across files.
- What does the cross-file integration pass check for?
- Data flow inconsistencies between modules, contradictory findings across per-file passes, and API contract violations.
- Confidence-based routing rule?
- High confidence → report directly to developers; low confidence → route to human review.
- Is raw self-reported model confidence reliable for routing on its own?
- No — it's uncalibrated, effectively the model judging itself, and must be validated against labelled data before use.
- How do you calibrate confidence thresholds correctly?
- Group findings into confidence bands and measure the share in each that labels confirm as correct; labels come from human verdicts or recorded outcomes, never a second model's verdicts.
- Documented principle for judging agent/review outcomes?
- Judge whether the correct final state was reached, not whether a specific process was followed.
- Example LLM-judge rubric dimensions from Anthropic's research system?
- Factual accuracy, citation accuracy, completeness, source quality, and tool efficiency.
- Why not flag only findings that 2 of 3 full-PR passes agree on?
- Each pass is still diluted, and subtle real bugs are caught intermittently, so consensus suppresses them — it trades recall for precision (sample question 12).
- What does the cross-file integration pass receive?
- Every per-file finding as structured data, with an instruction to report only cross-file issues and not restate local ones.
- Route a low-confidence, high-severity finding.
- To a human reviewer for triage. High/high → blocking comment; high conf/low sev → note; low/low → log only.