CCAR-F Prompt Engineering and Structured Output Practice Question
A developer is building a classification pipeline that routes support tickets into one of eight categories. They want Claude to return a category label and a confidence score between 0 and 1. The output must be parseable by a JSON parser without post-processing. They plan to use the Anthropic Messages API. Which approach best ensures the output is directly parseable JSON with the required fields?
⚠ Common exam trap
The trap here is thinking that a stop sequence on the closing brace will neatly end the JSON, when in fact it truncates the response and removes the closing brace.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Describe the JSON schema in the system prompt, prefill the assistant turn with `{`, and validate the response with a JSON parser.
Describing the schema in the system prompt gives Claude the keys and types to emit, and prefilling the assistant turn with `{` forces the response to begin as a JSON object with no preamble or markdown fence. Validating with a JSON parser catches rare deviations. Together these produce directly parseable output, unlike free-text formats, stop-sequence tricks, or high-temperature sampling.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Set `temperature` to 1 and rely on the model's creativity to produce varied but valid JSON.
Why it's wrong here
Higher temperature increases variability, which raises the risk of malformed JSON, missing fields, or extra commentary. Creativity is undesirable for structured classification output. Lower temperature is generally preferred for deterministic, schema-conforming responses. This option does nothing to enforce JSON structure and is likely to worsen parseability rather than improve it, so it fails the requirement.
- ✗
Ask Claude to return the category and confidence in a single sentence like 'Category: X, Confidence: 0.9'.
Why it's wrong here
A free-text sentence is not JSON and would require regex or string parsing, which the developer explicitly wants to avoid. It also risks inconsistent phrasing across responses, breaking downstream parsers. This approach fails the requirement of direct JSON parseability and introduces fragile string handling. The scenario demands structured, machine-readable output, which a sentence format does not provide.
- ✓
Describe the JSON schema in the system prompt, prefill the assistant turn with `{`, and validate the response with a JSON parser.
Why this is correct
Combining a clear schema description with an assistant-turn prefill of `{` produces raw JSON that starts with the opening brace, and validating with a parser catches any rare deviation. This is the recommended Anthropic pattern for guaranteed parseable JSON. The schema description tells Claude which keys and types to emit, while the prefill prevents preamble or code fences, making the output directly parseable.
- ✗
Use the `stop_sequences` parameter set to '}' so Claude stops as soon as it finishes the JSON object.
Why it's wrong here
Setting a stop sequence to '}' would truncate the response before the closing brace is emitted, producing invalid JSON. Stop sequences halt generation when the sequence appears, so the closing brace would be missing from the output. This actively breaks parseability. The correct use of stop sequences is to end generation after a delimiter, not to include the delimiter itself in the output.
About these practice questions
This CCAR-F question is part of Courseiva's 271-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Anthropic exam blueprint
This CCAR-F practice question is part of Courseiva's free Anthropic certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CCAR-F exam.