Claude Academy
Sign in

Practice — CCDV-F Domain 6: Prompt and Context Engineering (11%)

9 scenario-based MCQs. Answer key + explanations at the bottom.


Q1

A debugging assistant runs 60+ turn sessions with developers. Early turns establish reproduction steps and environment details that stay relevant in compressed form; recent turns carry the active investigation. Costs are climbing and the model has started re-asking questions answered 40 turns ago. Which context-management strategy fits best?

A. Sliding window: keep only the last 5 turns verbatim and drop everything older B. Progressive summarization: replace the oldest turns with a compact assistant summary C. Replay the full history every turn and rely on prompt caching to keep the cost flat D. Store every turn of the session in a vector store and retrieve only the relevant past turns on each new request

Q2

An agent calls a search_logs tool that can return 25K tokens of raw log lines per invocation. After three calls the conversation is bloated, latency has spiked, and the model starts missing instructions placed mid-context. Which change best addresses the root cause?

A. Raise max_tokens so the model has more room to process the large log payloads B. Add cache_control to each tool_result block so subsequent turns read the log payloads from the server cache C. Change the tool to return a filtered summary plus a reference for fetching full logs on demand D. Move the log output into the system prompt so the model weights it more heavily than mid-context text

Q3

You delegate a code audit to a subagent with the prompt: "Audit the modules we discussed above for the concurrency issue." The subagent returns a generic, irrelevant report. What is the most likely cause and fix?

A. The subagent starts with a fresh context; rewrite the brief to be self-contained with file paths and the issue description B. The subagent's model is too small for audit work; upgrade it to the same model the orchestrator uses C. The subagent's tool whitelist is too narrow; grant it the parent's full tool set so it can rediscover the missing context on its own D. Subagents cannot access the parent's repository files at all; rerun the audit inside the parent's own context window instead

Q4

A summarization app interpolates user-pasted web content directly into its system prompt template. Occasionally a pasted page contains text like "ignore all previous instructions," and the app's behavior shifts. Which restructuring best addresses this?

A. Add a system-prompt rule stating that any instructions found inside pasted content must always be ignored, never followed B. Set temperature to 0 so the model deterministically follows the original instructions on every request C. Prepend the app's fixed rules to every user message instead of relying on a system prompt at all D. Keep fixed rules in the system prompt and pass pasted content in the user turn, delimited as untrusted data

Q5

A nightly pipeline extracts vendor, total, and currency from invoices into JSON that downstream code consumes with no human in the loop. Which technique gives the strongest guarantee that output matches your schema?

A. Define an extraction tool with an input_schema and force it with tool_choice: {type: "tool", name: "extract_invoice"} B. Prefill the assistant turn with { so the model is forced to continue generating JSON C. Instruct "Respond only with valid JSON matching this schema" in the prompt and include a worked example of correct output D. Set temperature to 0 and add a stop_sequences entry so generation ends at the closing brace

Q6

Your service parses Claude's JSON output with json.loads. Roughly one request in a few hundred fails to parse and the endpoint returns a 500. Which production pattern should you adopt?

A. Wrap the parse in try/except and return an empty result object so the endpoint never surfaces a failure B. Set temperature to 0 so output becomes deterministic; once your test suite passes, the format cannot regress in production C. Validate against a schema; on failure, re-prompt with the validator's error message, cap retries around 3, then route to human review D. Append an instruction telling the model to verify that its JSON is valid before it finishes the same response

Q7

An extraction system pulls contract terms from PDFs into a database. Legal reviewers complain they cannot tell whether an extracted clause value is genuine or hallucinated without re-reading each contract in full. Which change best addresses their need?

A. Move extraction to the largest available model so that hallucinated values become negligible B. Have the model emit a self-reported confidence score alongside each extracted field C. Run each extraction twice with the same prompt and store a value only when both runs return the identical answer D. Require a source pointer (page/section) with each extracted field so reviewers can spot-check it

Q8

A 50-turn account-management agent fetched the user's plan tier in turn 4, then compacted early turns into a summary containing "user is on the Pro plan." In turn 48 it applies Pro-plan logic — but the user downgraded mid-conversation. Which practice prevents this class of bug?

A. Keep the original tool_result block verbatim in context rather than folding it into a summary B. Treat volatile facts as refresh-on-need: re-fetch before acting, and timestamp facts captured in summaries C. Pin the plan tier into the cached system-prompt prefix so that every subsequent turn sees the same authoritative value D. Instruct the agent to trust the most recent user message over anything stated in the summary

Q9

A ticket classifier's prompt describes its six categories in abstract prose. Outputs sometimes use synonyms for labels ("billing issue" vs "BILLING"), and edge cases land in different categories run to run. Which prompt change most directly fixes both problems?

A. Add more conditional prose rules to the prompt covering every observed edge case individually and explicitly B. Add few-shot examples showing the exact label strings, including one or two hard edge cases C. Raise temperature so the model explores the label space more broadly before committing D. Move the category definitions out of the system prompt and repeat them in every user message


Answers

Q1: B. Progressive summarization keeps recent detail high-fidelity while compressing older turns — exactly what a single long session with still-relevant early facts needs. A sliding window (A) drops the reproduction steps entirely, which is why the model re-asks. Full replay (C) still grows the context every turn — caching cuts cost on the stable prefix but doesn't fix "lost in the middle" or the growing suffix. Retrieval-on-demand (D) is the fit for very long-lived agents across sessions; for one conversation it adds infrastructure without beating a summary.

Q2: C. Huge tool outputs are a documented pitfall; the fix is to summarize/truncate in the tool and return a reference for on-demand retrieval, which removes the bloat at its source. max_tokens (A) caps output length and does nothing about input bloat. Caching the results (B) reduces re-read cost but the tokens still occupy the window, so the mid-context misses persist. System-prompt placement (D) doesn't shrink anything and pollutes the stable prefix with volatile data.

Q3: A. A subagent runs in its own fresh context window and sees none of the parent conversation, so "discussed above" resolves to nothing — the brief must be self-contained with paths, requirements, and constraints. Model size (B) is not the failure mode when the input itself is underspecified. A wider tool set (C) lets it search but not know what to search for, wasting tokens rediscovering known context. (D) is factually wrong — subagents can be given file tools; the isolation is of conversation context, not the filesystem.

Q4: D. The structural fix is separating trusted instructions from untrusted data: rules live in the system prompt, and pasted content arrives in the user turn clearly delimited as data to be summarized, not obeyed. A rule alone (A) is the tempting runner-up, but it leaves hostile text sitting in the privileged system slot where it competes directly with your instructions. Temperature (B) controls sampling randomness, not instruction-following under injection. (C) discards the system/user separation you actually need and repeats rules wastefully.

Q5: A. Forced tool use is the most reliable structured-output technique: the input_schema acts as the contract, and Claude must emit a tool_use block matching it. Prefill (B) is the runner-up — it guarantees the output starts as JSON but enforces no schema, so fields can be missing or mistyped. Prompt-only instruction (C) is the cheapest and least reliable of the three techniques. Sampling settings and stop sequences (D) shape generation but constrain neither well-formedness nor structure.

Q6: C. Never trust model output to be well-formed: validate after generation, feed the validator's error back on a re-prompt, cap retries (~3), and escalate to human review — the canonical validation loop. Swallowing errors (A) trades a visible failure for silent data corruption downstream. Temperature 0 (B) reduces variance but is not a well-formedness guarantee, so the failure still ships — just less often. A self-check instruction in the same pass (D) is still unverified model output; only external validation catches what the model believes is fine.

Q7: D. Provenance is the answer to auditability: a source pointer per field lets reviewers spot-check a value against its page and section without re-reading the contract. Double-running (C) is the plausible runner-up, but two runs can agree on the same hallucination and agreement still gives reviewers nothing to verify against. Self-reported confidence (B) is exactly the kind of confident output to be skeptical of — it isn't calibrated evidence. A larger model (A) lowers the rate but leaves every value unverifiable.

Q8: B. Tool results expire: the note's stale-data guidance is to prefer refresh-on-need over remember-forever for volatile facts and to mark when each summarized fact was retrieved. Keeping the raw tool_result verbatim (A) preserves a stale value at higher token cost — verbatim isn't fresh. Pinning it into the cached prefix (C) makes the stale value more authoritative and churns the cache when it changes. (D) fails because the user never restated the downgrade; recency of the message doesn't refresh the fact.

Q9: B. Few-shot examples demonstrate the exact output contract — literal label strings and how borderline tickets resolve — which fixes format drift and edge-case inconsistency in one move. Piling on conditional rules (A) is the runner-up trap: it re-creates the dilution failure where each added rule lowers the weight of every other rule. Higher temperature (C) increases run-to-run variance, the opposite of the goal. Repositioning the same abstract prose (D) changes placement, not clarity — the model still never sees what a correct answer looks like.