CCDV-F : Prompt & Context Engineering (Domain 6)
Domain 6 : Prompt and Context Engineering
This study guide serves as a technical resource for candidates preparing for the Claude Certified Developer – Foundations (CCDV-F) exam, specifically focusing on Domain 6: Prompt and Context Engineering. This domain represents 11.0% of the total exam weight and is subdivided into three critical areas: Context Engineering (3.8%), Prompt Engineering (4.6%), and Output Handling (2.6%).
The role of a Claude Developer is to bridge the model’s intelligence with production-ready systems. This requires moving beyond simple “chat” interactions to a rigorous engineering approach where context is managed as a finite resource, prompts are designed with structural integrity, and outputs are handled with programmatic skepticism.
1. The Architectural Role of Domain 6 in the CCDV-F Blueprint
Within the CCDV-F framework, Domain 6 acts as the interface layer between the logic of the application (Domain 2) and the intelligence of the model (Domain 5). While other domains focus on the “how” of API integration and agent loops, Domain 6 focuses on the “what”—the specific data and instructions passed to the model to ensure reliable, cost-effective, and accurate performance.
A Minimally Qualified Candidate (MQC) must demonstrate the ability to:
- Maintain model performance over long conversations by managing the context window.
- Prevent “context drift,” where the model loses track of its primary objective due to excessive or irrelevant information.
- Utilize structured prompting techniques (such as XML delimiters and few-shot sequences) to increase determinism.
- Implement defensive parsing and validation logic to handle model outputs in a production environment.
2. Context Engineering Mechanics (Subdomain 6.1)
Context Engineering is the practice of managing the lifecycle of data within the model’s context window. For Claude models—including Opus, Sonnet, and Haiku—the context window is extensive, but utilizing it inefficiently leads to increased latency, higher costs, and degraded reasoning capability.
Context Window Management
Effective management begins with understanding the limits of the model being utilized. While Claude offers a massive context window, the Developer must treat it as a premium resource. Every token added to the context is a token that the model must process at every step of a multi-turn conversation.
- Initial State: The conversation starts with high clarity.
- Expansion: As tool outputs, user queries, and model responses accumulate, the “bloat” increases.
- Saturation: Eventually, the model may begin to overlook instructions placed at the beginning of the context (the “middle-of-the-document” phenomenon).
Preventing Context Drift and Bloat
Context drift occurs when the model shifts its focus toward irrelevant details found in previous turns of a conversation. Bloat refers to the accumulation of unnecessary data that does not contribute to the current task.
Pruning Tool Outputs: When an agent uses a tool (e.g., a SQL database search or a web search), the raw output can be massive. A Developer should implement logic to prune these results.
- Example: If a tool returns 500 lines of JSON but only 5 lines are relevant to the user’s specific query, the application should filter the data before passing it back to Claude.
- Benefit: This preserves the context window for actual reasoning and reduces the cost of subsequent API calls.
Compaction Strategies: For long-running sessions, compaction involves summarizing the history.
- Rolling Window: Keeping only the most recent $N$ turns in full detail.
- Summarization: Periodically asking a smaller model (like Claude Haiku) to summarize the previous 20 turns into a concise state-summary, which is then passed as the new “starting point” for the primary model.
Context Isolation through Subagents
One of the most effective ways to manage context in complex systems is isolation. Rather than having a single agent manage 50 tools and a 20-turn history, a Developer can use the Claude Agent SDK to delegate tasks to subagents.
- The Manager Agent: Holds the high-level goal and user context.
- The Worker Subagent: Only receives the specific data and tools needed for a single sub-task.
- Result: The worker’s context remains “clean,” preventing the bloat from the manager’s history from affecting the sub-task’s accuracy.
3. Foundational Prompt Engineering Techniques (Subdomain 6.2)
Prompt Engineering in CCDV-F is treated as a software engineering task rather than a creative writing exercise. It involves the use of structured sequences and clear hierarchies to guide model behavior.
Instruction Clarity and Iterative Refinement
Instructions must be explicit and unambiguous. A Developer should avoid vague adjectives and instead use quantitative constraints or specific formatting rules.
- Vague: “Give me a short summary.”
- Explicit: “Provide a three-sentence summary of the provided text. Format the output as a JSON object with the key ‘summary’.”
System vs. User Message Placement
The Messages API distinguishes between “System” and “User” roles. This hierarchy is critical for model steering.
- System Prompt: Defines the core persona, global constraints, and static rules. This is where the “hard” instructions should live.
- User Message: Contains the specific request or new data.
- Tool Description: Instructions can also be embedded in tool definitions. If a model consistently fails to use a tool correctly, the Developer should first refine the description of that tool within the prompt.
Structured Few-Shot Sequences
Few-shot prompting—providing examples of the desired input/output mapping—is the most reliable way to improve performance on complex tasks.
- Zero-shot: No examples.
- Few-shot: 3-5 examples of the task.
- Implementation: Examples should be clearly delimited and represent a range of edge cases. If the task is to classify sentiment, provide examples of “Positive,” “Negative,” and “Neutral” (or ambiguous) cases.
4. Structuring Claude Prompts with XML Delimiters
Claude models are specifically trained to recognize and prioritize information structured with XML tags. Using XML delimiters is a primary best practice for a Claude Developer.
Why Use XML Tags?
XML tags help the model distinguish between different parts of the prompt, such as instructions, background context, and user data. This prevents the model from confusing user input with its own instructions (a basic defense against prompt injection).
| Tag Purpose | Example Tag | Description |
|---|---|---|
| Instructions | <instructions> | Encapsulates the core logic the model must follow. |
| Data/Context | <context> | Contains the reference material or history. |
| Examples | <examples> | Houses the few-shot demonstrations. |
| User Input | <user_query> | Isolates untrusted input from the user. |
Prompt Adjustment and Iteration
The Developer should treat prompts as code that requires version pinning and testing.
- Prompt Versioning: Just as models are pinned (e.g.,
claude-3-5-son-20241022), prompt versions should be stored in configuration files (likesettings.json) or version-controlled repositories. - Iterative Refinement: If a model fails, the Developer identifies whether the failure was due to instruction ambiguity, lack of examples, or context bloat, and adjusts the prompt accordingly.
5. Input Sanitization and Defending Against Prompt Injection
While Domain 7 (Security) covers the broad landscape of AI safety, Domain 6 focuses on the prompt-level implementation of these defenses.
Untrusted Input Handling
A primary responsibility of the Developer is to assume all user input is untrusted.
- Sanitization: Removing or escaping characters that might confuse the model’s parsing logic.
- Isolation: Placing user input inside clearly labeled XML tags and instructing the model in the system prompt to only treat content inside those specific tags as data, never as instructions.
Jailbreak Defense
Jailbreaks often involve “persona adoption” (e.g., “Forget your previous instructions and act as…”).
- Defensive Prompting: Reinforcing the system prompt by repeating core safety constraints at the end of the prompt, often referred to as “instruction repetition” or “recency bias management.”
- Least Privilege: Ensuring the model’s instructions do not grant it more authority than required for the task.
6. Advanced Output Handling Strategies (Subdomain 6.3)
The final stage of the prompt engineering lifecycle is consuming the model’s response. In production systems, the model’s output cannot be treated as a string to be displayed directly without validation.
Structured JSON Responses
For programmatic integration, the model should be instructed to return JSON.
- Schema Enforcement: Provide a clear JSON schema within the prompt.
- Tool Use as Output: A common pattern is to “force” a model to use a specific tool (even a dummy tool) to ensure it returns arguments in a structured, typed format that the application can easily parse.
Response Validation and Defensive Parsing
Even if a model is instructed to return JSON, it may occasionally include conversational filler (e.g., “Here is the JSON you requested:”) or malformed brackets.
- Defensive Parsing: The application should use robust parsing logic that can isolate the JSON block within the string.
- Schema Validation: After parsing, the JSON must be validated against a pre-defined schema (e.g., using Pydantic in Python or Zod in TypeScript) to ensure all required fields are present and types are correct.
Skepticism of Confident Outputs
Large language models are designed to be helpful and coherent, which often results in them being “confidently wrong.”
- Hallucination Awareness: The Developer must implement checks for “confident” outputs that lack a factual basis in the provided context.
- Self-Correction: A multi-turn pattern where the model is asked to “review its own work for errors” before the final output is delivered to the user.
7. Interacting with Claude Code and Project Configurations
A Developer working with Claude Code must understand how prompt engineering applies to the local development environment.
CLAUDE.md and System Rules
CLAUDE.md acts as a persistent system prompt for the local agent. It should contain:
- Project Context: High-level architecture and tech stack.
- Coding Standards: Explicit rules about naming conventions, error handling patterns, and testing requirements.
- Iteration: As the project evolves, the Developer updates
CLAUDE.mdto prune old instructions and add new project-specific constraints.
Settings and Plugins
Configuration management (Domain 2) overlaps with Domain 6 here. The settings.json file controls the environment in which the prompts are executed. The Developer manages model version pinning here to ensure that prompt engineering optimized for Sonnet 3.5 isn’t unexpectedly executed against a newer model that may interpret the instructions differently.
8. Claude Prompt Optimization: Caching and Cost Management
Prompt engineering is not just about quality; it is about efficiency. The use of Prompt Caching changes how a Developer structures context.
Prompt Caching Breakpoints
Anthropic’s prompt caching allows Developers to reuse large blocks of context (like system prompts, tool definitions, and long documents).
- Cost Efficiency: Caching reduces the cost of tokens that are reused across multiple calls.
- Latency: Cached prompts are processed faster.
- Breakpoint Strategy: The Developer should place the “static” parts of the context (instructions, few-shot examples) at the beginning of the prompt and mark them as cacheable. Content that changes frequently (user query) should be placed after the cache breakpoint.
Model Selection Tradeoffs
Domain 6 requires the Developer to select the appropriate model tier based on the complexity of the prompt logic.
- Opus: Best for highly complex reasoning and “deep” prompt following.
- Sonnet: The standard for most production builds, balancing intelligence and speed.
- Haiku: Best for simple tasks, summarization, or acting as a “subagent” for trivial logic.
| Capability | Opus | Sonnet | Haiku |
|---|---|---|---|
| Reasoning Depth | Highest | High | Moderate |
| Prompt Following | Most Precise | Very Strong | Good for simple rules |
| Latency | High | Low | Lowest |
| Context Limit | 200k+ | 200k+ | 200k+ |
9. Evaluation and Testing Methodologies for Prompts
Prompt Engineering is incomplete without Evaluations (Evals). A Developer must move away from “vibe-based testing” toward structured measurement.
Designing Strong Evals
To test a prompt change, a Developer needs:
- A Golden Dataset: A collection of inputs and “correct” reference outputs.
- Rubrics: Specific criteria for success (e.g., “JSON is valid,” “Answer contains the order ID,” “Tone is professional”).
- Automated Grading: Using a more powerful model (Opus) to grade the outputs of the production model (Sonnet) against the rubric.
Trace Analysis and Debugging
When a prompt fails to produce the desired result, the Developer uses trace analysis.
- Isolating the Failure: Was the failure in the model’s reasoning, or was it a failure in the application’s context management (e.g., the relevant data was pruned during compaction)?
- Debugging Tool Use: Examining the arguments the model generated for a tool call to see if they follow the provided schema.
10. Summary of Best Practices for Prompt and Context Engineering
For success in the CCDV-F Domain 6 exam, the candidate should internalize the following “Engineer’s Mindset”:
- Structure is King: Use XML tags and clear delimiters to prevent the “soup of text” phenomenon.
- Context is Expensive: Prune, compact, and isolate. Do not pass the model information it does not need.
- Trust But Verify: Use Pydantic or Zod to validate outputs. Never assume the model followed the JSON schema perfectly.
- System Prompts are for Rules: Use the system prompt for personas and constraints; use user messages for tasks and data.
- Evals are Mandatory: You haven’t “engineered” a prompt until you have measured its performance across a representative dataset.
11. Glossary of Key Claude AI Development Terms
- Context Window: The total amount of information (tokens) the model can consider at one time.
- Context Drift: A phenomenon where a model’s focus shifts away from the original goal due to excessive conversation history.
- Context Bloat: The accumulation of irrelevant tokens that increase cost and latency without improving accuracy.
- Pruning: The act of removing irrelevant portions of data (specifically tool outputs) before passing them to the model.
- Compaction: Summarizing or condensing previous conversation turns to preserve space in the context window.
- Subagents: Independent model instances used to isolate tasks and context, preventing one task’s bloat from affecting another.
- Few-Shot: A prompting technique involving providing the model with a few examples of desired input/output pairs.
- XML Delimiters: Using tags like
<context>or<rules>to help Claude distinguish between instruction sets and data. - System Prompt: A high-level instruction set that defines the model’s persona and fundamental operational rules.
- Prompt Injection: An attempt by a user to override a model’s system instructions by providing malicious commands in the user input field.
- Structured Output: Model responses formatted as machine-readable data (typically JSON) for integration into software.
- Defensive Parsing: Code logic designed to safely extract and validate model outputs, even if they contain extraneous text.
- Hallucination: A confident but factually incorrect or unsupported statement generated by the model.
- Prompt Caching: A feature that allows for the storage and reuse of static context blocks to reduce cost and latency.
- Messages API: The primary interface for interacting with Claude, supporting distinct roles for system, user, and assistant.
- Claude Code: Anthropic’s CLI-based development agent that uses local project context for software engineering tasks.
- CLAUDE.md: A project-level configuration file used to provide instructions and context to Claude in a development environment.
- Evaluation (Eval): A structured test designed to measure a model’s performance on a specific task against a defined rubric.
- Token: The basic unit of text processing for LLMs; approximately 0.75 words.
- Golden Dataset: A verified collection of inputs and ideal outputs used as a benchmark for testing prompt changes.
12. Domain 6 Short Answer Practice Questions
Q1: What is the primary benefit of using XML tags in Claude prompts? Answer: XML tags help Claude distinguish between different structural components of a prompt, such as instructions vs. untrusted user data, which improves instruction-following and helps prevent prompt injection.
Q2: How does a “subagent” architecture improve context management? Answer: It provides context isolation, ensuring that a subagent only receives the specific data needed for its task, thereby preventing context bloat and drift from the main conversation.
Q3: When should a Developer use “compaction” instead of “pruning”? Answer: Compaction (summarization) is used when the history of a long conversation is still relevant but too large, whereas pruning is used to remove entirely irrelevant data, like excessive tool output.
Q4: In the Messages API, what should ideally be placed in the “System Prompt”? Answer: The system prompt should contain the model’s persona, global operational constraints, safety guardrails, and persistent formatting rules.
Q5: What is “defensive parsing” in the context of output handling? Answer: It is the practice of using logic to extract valid structured data (like JSON) from a model’s response while ignoring conversational filler or correcting minor formatting errors.
Q6: Why is skepticism important when handling “confident” model outputs? Answer: Because models can hallucinate with high confidence; the application must validate these outputs against ground-truth data or schemas before using them in critical workflows.
Q7: How does Prompt Caching affect the placement of instructions in a prompt? Answer: Static instructions and examples should be placed at the beginning of the prompt to be cached, while dynamic user queries are placed after the cache breakpoint.
Q8: What is the difference between Zero-shot and Few-shot prompting? Answer: Zero-shot provides only instructions, while Few-shot provides instructions plus one or more examples of how to perform the task.
Q9: How can a Developer use “Claude Code” to manage project-wide prompt instructions?
Answer: By utilizing a CLAUDE.md file to store architectural context and coding standards that the local agent should follow for every task in that repository.
Q10: What is the purpose of a “Golden Dataset” in Domain 6? Answer: It provides a consistent benchmark for evaluating whether a change in prompt engineering actually improved the model’s performance on a specific task.
13. Domain 6 Open-Ended Design Practice Questions
- Scenario: You are building a customer support agent that has access to a tool for searching order history. The tool often returns several pages of data. Design a context management strategy to ensure this agent remains accurate over a 30-minute conversation.
- Scenario: You find that a model is occasionally ignoring safety instructions in the system prompt when the user provides a very long and complex query. Propose three prompt engineering adjustments to reinforce the model’s adherence to the system rules.
- Scenario: You need Claude to return a complex nested JSON object representing a software deployment plan. Describe the end-to-end workflow from prompt design (using schemas) to post-response validation.
- Scenario: A multi-agent research system is suffering from high costs and high latency. Analyze how context isolation and prompt caching could be used to optimize this system without losing data integrity.
- Scenario: You are tasked with creating a “Code Reviewer” agent using Claude Code. Explain how you would structure the
CLAUDE.mdfile and what delimiters you would use to ensure the agent correctly distinguishes between the code being reviewed and the review instructions.
Leaderboard
No scores saved yet. Be the first!
25 Questions — Domain 6 : Prompt and Context Engineering
Expand any question to reveal the correct answer and explanation.
-
1 A developer is building a high-stakes financial advisory agent. According to the CCDV-F framework, where should the primary constraints regarding mandatory KYC compliance checks be placed to minimize the risk of the model bypassing them during a long session?
Consider the distinction between probabilistic model guidance and deterministic application control.
Programmatic execution gates or hooks in the application code
For safety and financial compliance, programmatic enforcement via hooks is more reliable than probabilistic prompt instructions, which have a non-zero failure rate.
-
✗ The top-level system parameter of the Messages API
While system prompts establish baseline behavior, they are still probabilistic and can be subject to context drift in complex or adversarial sessions.
-
✗ A specialized 'Compliance' subagent with its own context window
Subagents provide isolation but do not replace the need for deterministic enforcement in the execution layer for high-consequence actions.
-
✗ Repeated reinforcement instructions within the user message array
Repeated instructions contribute to context bloat and can still be overridden by later conversational context or prompt injection.
-
-
2 When managing long-running agentic workflows, which strategy is most effective for preventing 'context drift' where the model begins to lose track of initial instructions?
Think about how architectural separation can keep the model's 'working memory' focused.
Context isolation using subagents for specific multi-step tasks
Using subagents allows the coordinator to maintain a clean context by delegating details to isolated windows, preventing the main thread from becoming bloated.
-
✗ Scaling the context window to the maximum allowed token limit
Simply increasing the window size often exacerbates drift and bloat by including irrelevant or distracting historical data.
-
✗ Moving all task-specific data into the system prompt
System prompts are for baseline constraints; saturating them with task data leads to 'bloat' and reduces the model's focus on core instructions.
-
✗ Increasing the sampling temperature to encourage instruction following
Higher temperature increases randomness and variability, which typically decreases adherence to strict constraints and increases drift.
-
-
3 To optimize token usage and maintain performance, a developer implements 'tool output pruning.' Which of the following describes the best practice for this technique?
Focus on managing the relevance and volume of data the model must process in its history.
Removing or summarizing large tool results that are no longer relevant to the current reasoning step
Pruning or compacting tool outputs reduces context bloat while preserving the semantic summary necessary for the agent's next decision turn.
-
✗ Setting a hard limit on the number of tool calls permitted per session
Limiting the number of calls does not address the size of the data within the context window, only the frequency of interactions.
-
✗ Converting all tool outputs to a compressed binary format before submission
Claude requires text or structured data to interpret tool results; binary formats would be incomprehensible to the model.
-
✗ Hard-coding tool results directly into the system prompt to avoid repetition
Tool results belong in the message history as assistant/user turn sequences to maintain a valid conversation trajectory.
-
-
4 When designing complex few-shot sequences for structured JSON extraction, what is the most effective way to improve the model's performance on ambiguous edge cases?
Quality of guidance in examples usually outweighs the quantity of data.
Include 2-4 examples that demonstrate both the target format and the internal reasoning for the decision
Few-shot examples are most effective when they provide both the pattern and the underlying logic, especially for tasks involving classification or extraction.
-
✗ Provide at least 10 simple examples to maximize the volume of training data
A high volume of simple examples can lead to over-fitting on easy cases while failing to help the model navigate complex logic or edge cases.
-
✗ Randomize the placement of system vs user roles within the examples
Role consistency is vital for the model to understand the interaction pattern; role switching would likely confuse the model's turn-taking logic.
-
✗ Use a single, extremely long example that covers every possible field
A single example, no matter how long, provides less diversity than multiple targeted shots and may cause the model to miss subtle distinctions.
-
-
5 A developer is implementing 'defensive parsing' for a Claude-powered system that consumes generated JSON. Which behavior demonstrates this principle?
Focus on the robustness of the code that receives the model's response.
Implementing fallback strategies to handle missing keys or malformed structures in the application layer
Defensive parsing assumes that generative outputs may occasionally deviate from schemas and prepares the code to handle these failures gracefully.
-
✗ Instructing the model to retry the response until it passes a strict regex check
While retries are a tactic, defensive parsing refers to the robustness of the consuming code, not just the model's generation attempts.
-
✗ Increasing the max_tokens parameter to ensure the JSON object is never truncated
Token limits prevent truncation but do not ensure the internal validity or structural correctness of the generated JSON.
-
✗ Trusting 'confident' model outputs and bypassing validation for simple tasks
Skepticism toward confident output is a core principle; even seemingly simple generations require validation to ensure production reliability.
-
-
6 In the context of CCDV-F, why is it recommended to place input sanitization and delimiters around user-provided content within a prompt?
Consider how a model might confuse data with instructions if they are not properly separated.
To clearly demarcate untrusted input and mitigate prompt injection risks
Sanitization and clear boundaries help the model distinguish between developer instructions and potentially adversarial user data.
-
✗ To reduce the overall token count of the request
Adding delimiters and sanitization logic actually increases the token count, albeit for a necessary safety benefit.
-
✗ To ensure the model always outputs a response in a specific language
Language constraints are managed through system instructions or few-shot examples, not through input delimiters.
-
✗ To bypass the need for a system prompt entirely
Demarcating input is a secondary safety layer and does not replace the foundational role of the system prompt in establishing constraints.
-
-
7 When a developer encounters 'semantic errors' (e.g., a field is syntactically correct but contains impossible values) in a Claude-generated response, which action is most appropriate according to architectural best practices?
Think about whether the issue is the 'shape' of the data or the 'meaning' of the data.
Implementing a validator in the application layer to catch and handle the logical error
Semantic errors represent a failure of logic that requires external validation, as the model may generate syntactically valid but factually incorrect data.
-
✗ Switching to a larger model tier immediately to solve the accuracy issue
Model tier changes are expensive and may not address specific logical edge cases that can be caught more efficiently by a validator.
-
✗ Updating the tool_use schema to include stricter data types
Schemas primarily handle syntax (e.g., string vs number); semantic logic (e.g., 'age' must be $>0$) usually requires separate validation.
-
✗ Lowering the sampling temperature to $0.0$
While temperature $0.0$ helps with consistency, it does not prevent the model from confidently asserting incorrect semantic values.
-
-
8 A developer needs to maintain the same set of complex formatting rules across multiple different tasks. Where should these rules be placed for maximum efficiency and maintainability?
Where can instructions be defined once to serve as the 'global' personality or ruleset for a model?
In a centralized system prompt used by a coordinator agent
Centralizing baseline formatting in the system prompt ensures consistency across the session and reduces the need to repeat rules in every user turn.
-
✗ In the CLAUDE.md file of each specific project directory
CLAUDE.md is for repository-level development instructions (Claude Code), not necessarily for the operational prompting logic of a shipped application.
-
✗ At the end of every individual user message for reinforcement
Repeating instructions in every turn causes massive context bloat and increases costs without guaranteeing better adherence.
-
✗ Within the description field of every tool defined for the agent
Tool descriptions should focus on the tool's function and arguments, not on general application-wide formatting rules.
-
-
9 Which field in the Messages API response should a developer monitor to differentiate between a successful task completion and an incomplete JSON object due to context window exhaustion?
Look for a parameter that explains the 'why' behind the termination of a response.
stop_reason
The 'stop_reason' field indicates whether the model finished naturally ('end_turn') or was cut off by limits ('max_tokens'), which is critical for identifying malformed JSON.
-
✗ usage.output_tokens
Token usage counts the volume of output but does not provide the semantic reason for why the generation ceased.
-
✗ model
The model field simply identifies which version of Claude generated the response and has no bearing on termination state.
-
✗ content.type
Content type identifies whether the block is text or tool use, but does not indicate if that block was fully completed.
-
-
10 When constructing a prompt for 'Structured Data Extraction,' why is 'segmented accuracy' considered a superior metric to 'aggregate accuracy'?
Consider the difference between a 'broad' grade and a 'detailed' diagnostic report.
It identifies specific document types or fields where the model consistently fails
Segmented accuracy reveals patterns of failure that aggregate percentages hide, allowing for targeted prompt or schema refinement.
-
✗ It allows the developer to use the Batch API more effectively
The Batch API is a delivery mechanism; the way accuracy is measured is independent of whether processing is real-time or batched.
-
✗ It automatically adjusts the context window to fit the data
Metrics are for evaluation and do not dynamically alter the model's operational context parameters.
-
✗ It prevents the model from generating confident but incorrect hallucinations
Measurement occurs after generation; it does not directly prevent hallucinations, though it helps diagnose them.
-
-
11 A developer wants to use Claude to transform a messy log file into a clean JSON array. The model frequently omits relevant fields. Which prompt engineering technique is most likely to resolve this?
Show, don't just tell, the model what a successful output looks like.
Adding 'multi-shot' examples that specifically include difficult or non-standard entries
Few-shot (multi-shot) examples demonstrate the expected handling of complex inputs, which is more effective than simple instructions for extraction tasks.
-
✗ Placing the JSON schema at the very end of the user message
Placement can help, but for omission issues, the model usually needs concrete examples of what NOT to skip rather than just a schema definition.
-
✗ Using a 'Thinking' model and setting the effort level to high
Thinking can help with reasoning, but extraction consistency is typically improved through pattern matching via examples rather than raw reasoning effort.
-
✗ Instructing the model to 'Be very careful and do not skip anything'
Vague superlative instructions are often ignored or have minimal impact compared to structural changes or examples.
-
-
12 Which of the following describes the risk of 'Context Bloat' in an agentic loop?
Think about what happens to a conversation's 'noise level' as it goes on too long without cleaning.
The accumulation of redundant tool outputs and historical turns degrades model focus and increases latency/cost
Context bloat occurs when irrelevant data fills the window, leading to increased costs and potential performance degradation.
-
✗ The model generates too many tokens in a single response, exceeding max_tokens
Exceeding max_tokens is a truncation issue, not necessarily a 'bloat' issue caused by historical context.
-
✗ User messages are too short for the model to understand the intent
Insufficient information is the opposite of bloat, which is characterized by excessive, irrelevant information.
-
✗ The system prompt is too short to establish necessary constraints
A brief system prompt may lead to ambiguity, but 'bloat' refers specifically to the accumulation of data in the session window.
-
-
13 Under the CCDV-F Domain 6 standards, what is the 'skepticism toward confident output' principle intended to address?
Why shouldn't you take a model's 'assured' tone at face value in a production environment?
The tendency of LLMs to assert incorrect information or malformed JSON with high linguistic certainty
LLMs can be confidently wrong (hallucinate); developers must implement validation regardless of the model's apparent certainty.
-
✗ The risk that users will not trust the model if it provides a short response
The principle is for the developer building the system, not the end user's perception of response length.
-
✗ The likelihood that the model will refuse to answer a valid prompt
Refusals are a safety or capability issue; skepticism refers to auditing the answers the model *does* give.
-
✗ The failure of the model to use the most expensive tier for a task
Model selection is a cost/optimization decision and is unrelated to the linguistic confidence of the model's output.
-
-
14 When configuring a Claude agent to use tools, why should 'tool descriptions' be treated as a primary prompt engineering surface?
How does the model know that a specific set of parameters corresponds to a specific real-world action?
They provide the model with the necessary context and rules for when and how to invoke external functions
The description is the model's only source of information about a tool's purpose; poorly written descriptions lead to incorrect or missed tool calls.
-
✗ They are used to encrypt the data sent to the API
Tool descriptions are plain text instructions and provide no cryptographic or encryption functions.
-
✗ They replace the need for JSON schemas in the API request
Descriptions complement schemas; the schema defines the structure, while the description defines the intent and use case.
-
✗ They allow the developer to bypass token limits for tool results
Descriptions are part of the input context and contribute to token usage; they do not provide a way to circumvent limits.
-
-
15 A developer needs to ensure that Claude strictly follows a set of brand voice guidelines. In a multi-turn conversation, where is the most 'stable' place to put these instructions?
Where are 'global' rules defined in the Messages API architecture?
The system prompt
The system prompt is the most stable location for persistent behavioral rules and constraints that should apply across all turns of a conversation.
-
✗ The first user message
Instructions in the first user message are more likely to be 'diluted' or ignored as the conversation continues and the context window shifts.
-
✗ The most recent user message
While highly influential for the immediate turn, instructions here must be repeated constantly, leading to bloat and inefficiency.
-
✗ A specialized 'Brand' tool that the model can call
A tool is for external actions or data retrieval; stylistic guidelines are better handled through the core instructions.
-
-
16 What is the primary benefit of 'prompt caching' in the context of prompt engineering for large-scale applications?
How can you make a prompt with 50 examples run as fast as a prompt with zero examples?
It significantly reduces latency and cost for requests that reuse large blocks of instructions or examples
Prompt caching allows the model to bypass re-processing large static portions of a prompt, making few-shot or instruction-heavy prompts more viable.
-
✗ It prevents the model from generating repetitive content
Caching relates to input processing and cost/latency; it does not directly control the diversity or repetition of the model's generated output.
-
✗ It allows the model to access data that was not included in the original request
Caching only applies to content already provided in the request history; it is not a retrieval mechanism for external data.
-
✗ It encrypts the conversation history for better PII security
Caching is a performance and cost optimization tool and does not provide encryption or PII protection.
-
-
17 A developer is building a system that extracts PII from documents. They find the model occasionally misses fields when documents are over $50$ pages. What is the most 'architecturally sound' solution to this context management problem?
Think about 'divide and conquer' as a strategy for long-form data.
Chunk the document and use a subagent to process each chunk independently, then aggregate the results
Chunking and task isolation prevent the model from becoming overwhelmed by long context, improving extraction accuracy for large documents.
-
✗ Switch to Claude 3 Opus to take advantage of its superior reasoning
While Opus is powerful, even high-tier models can suffer from 'middle-of-the-document' neglect in extremely large context windows.
-
✗ Append 'Look very carefully at every single page' to the end of the user prompt
Linguistic pleas for attention rarely solve structural issues related to context window saturation.
-
✗ Compress the document text by removing all vowels before processing
Destroying the semantic integrity of the input data makes it impossible for the model to extract accurate information.
-
-
18 Which scenario justifies the use of a 'forced tool choice' ($tool\_choice = \{\"type\": \"tool\", \"name\": \"...\"\}$) configuration?
When might you want to take the 'choice' away from the model and mandate an action?
When a specific tool must be executed as the very first step in a workflow (e.g., identity verification)
Forced tool choice ensures the model invokes a specific function immediately, bypassing the usual probabilistic decision of whether to use a tool.
-
✗ When the developer wants to reduce the cost of tool calls
Forcing a tool does not change the pricing of the API call or the tokens consumed by the tool's result.
-
✗ When the model is failing to understand the system prompt's instructions
Forcing a tool handles invocation order but does not fix underlying issues with general instruction following or reasoning.
-
✗ When the developer wants to disable all other tools for the entire session
Tool choice can be configured per-turn; it is not a global session-level disabling mechanism for other tools.
-
-
19 According to the CCDV-F Domain 6.2, what is a common pitfall when placing instructions in both the system prompt and the user message?
What happens when the 'global' boss and the 'immediate' boss give different orders?
Contradictory or competing instructions can cause unpredictable model behavior or refusals
Instruction placement across components requires coordination; conflicts between the system's global rules and the user's specific task can lead to failure.
-
✗ The model will always ignore the system prompt in favor of the user message
Claude generally prioritizes system prompts for baseline constraints, although recent user messages have high influence on immediate turns.
-
✗ Placing instructions in both locations automatically doubles the token cost
Cost is based on total unique tokens; duplication increases count, but it doesn't 'automatically double' unless the full text is repeated.
-
✗ System prompts can only contain $500$ characters if user messages are present
There is no such specific character limit; limits are governed by the total context window of the model version being used.
-
-
20 A developer is using Claude to generate SQL queries. The model often generates queries that refer to non-existent tables. Which few-shot technique is best for fixing this?
How can you provide the model with the 'ground truth' of your specific environment?
Provide examples that include a 'schema look-up' step or examples of the specific table names in use
Grounding the model with few-shot examples that utilize the correct schema is the most effective way to prevent hallucinations of non-existent data structures.
-
✗ Use a system prompt that says 'Only use valid tables'
Vague instructions to 'be valid' do not provide the model with the actual list of valid tables it needs to reference.
-
✗ Provide 100 examples of generic SQL queries found online
Generic examples do not ground the model in the developer's specific database schema, which is the root cause of the error.
-
✗ Enable 'Extended Thinking' with a high effort budget
Thinking can help with query logic, but it cannot 'invent' the correct table names if they haven't been provided in the context.
-
-
21 In context engineering, what is the purpose of 'context compaction'?
Think of this as a 'digest' or 'executive summary' of a long meeting.
Summarizing previous conversation turns to retain core meaning while staying under context limits
Compaction allows long histories to be preserved semantically without consuming the entire token budget of the context window.
-
✗ Encoding the entire prompt into a single line of text
Compaction is a semantic summary process, not a whitespace or formatting removal process.
-
✗ Forcing the model to use the most efficient model tier (e.g., Haiku)
Compaction refers to data management within a prompt, not the selection of the model infrastructure itself.
-
✗ Reducing the number of tools available to the agent
Reducing tools is 'pruning' the capability set, whereas compaction refers specifically to the message history and context data.
-
-
22 A developer needs Claude to output a valid JSON object. They find the model occasionally adds conversational filler (e.g., 'Sure, here is your JSON:') before the code block. What is the most reliable way to prevent this using prompt engineering?
How do you establish 'the rules of the game' before the conversation starts?
Include a system prompt instruction specifying 'Output JSON only' and provide few-shot examples with no pre-amble
Clear constraints in the system prompt combined with formatting-only examples are the standard way to enforce strict output formats.
-
✗ Place the instructions in a tool description instead of the main prompt
Tool descriptions govern how a tool is *called*, not how the model provides its final textual or structured response to the user.
-
✗ Use a higher temperature setting to encourage the model to skip common phrases
Higher temperature increases randomness, which is the opposite of the predictability needed for strict formatting.
-
✗ Increase the frequency penalty in the API parameters
Frequency penalties discourage repeated words but do not inherently prevent the first occurrence of a conversational preamble.
-
-
23 When building an agent with the Claude Agent SDK, why might a developer choose a 'supervised' multi-agent pattern over a single autonomous agent?
Think about the benefit of having a 'manager' check the 'specialist's' work.
To improve reliability by having a coordinator agent validate the subagent's output before continuing
Supervision patterns add a layer of review and planning, which is more reliable for complex tasks than a single-loop autonomous agent.
-
✗ To reduce the cost of the overall workflow
Multi-agent systems are typically more expensive because they involve multiple API calls and coordinated processing turns.
-
✗ To bypass the need for an API key
All interactions with Claude require an API key regardless of the architectural pattern (agent vs simple call).
-
✗ To ensure the model never uses prompt caching
Architectural patterns do not prevent the use of caching; in fact, agents often benefit greatly from caching instructions.
-
-
24 Which technique is recommended for preventing 'prompt injection' where a user tries to hijack the model's instructions?
Don't rely on the model to 'behave'; rely on the system to 'constrain'.
Separating untrusted user input into specific content blocks and applying programmatic guardrails
Isolation and programmatic checking are the only effective ways to mitigate injection; prompt-level 'pleas' for safety are easily bypassed.
-
✗ Adding 'Please ignore all other instructions' to the start of the system prompt
Instructions like this can actually be used *by* attackers and do not provide an enforceable technical barrier.
-
✗ Switching to a model with a smaller context window
Context window size is unrelated to the model's susceptibility to adversarial prompt instructions.
-
✗ Using only one-shot examples to minimize attack surface
The number of shots does not impact whether the user input can hijack the model's turn-taking logic.
-
-
25 What is the primary role of the 'system' role in a Messages API request?
Think of this role as the 'Constitution' or 'Primary Directive' of the agent.
To provide the global instructions, personality, and operational constraints for the entire conversation
The system prompt acts as the foundational layer of instructions that the model prioritizes throughout the session.
-
✗ To act as the transcript of previous user-assistant turns
The 'messages' array handles the interaction history; the system prompt is for top-level instructions.
-
✗ To define the JSON schema for tool outputs
Tool schemas are defined within the 'tools' parameter of the API request, not in the system prompt.
-
✗ To store the API key for the request
API keys are typically sent in the request headers, not within the prompt roles.
-