CCAR-F Prompt Engineering and Structured Output Practice Question
You are building an application that uses the Anthropic API to classify customer support tickets into exactly one of five categories: Billing, Technical, Account, Feature Request, or Other. You require the output to be a JSON object with a single field "category" and a value from that list. During testing, you notice that for ambiguous tickets the model sometimes returns a different key name, such as "ticket_category", or wraps the JSON in markdown code fences, causing parsing failures. You need to enforce the schema reliably while keeping latency and cost low. Which approach is most effective?
⚠ Common exam trap
The trap here is assuming that a detailed system prompt or few-shot examples can guarantee JSON schema compliance, when only structured mechanisms like tool use provide enforceable constraints.
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
✓
Use the Anthropic API's tool use feature by defining a tool with an input schema that specifies the required "category" field and its allowed enum values, then force the model to call that tool.
Forcing the model to use a tool with a strict input schema ensures the output conforms exactly to the required JSON structure, including the key name and allowed enum values. Unlike prompt instructions or temperature adjustments, tool use provides a hard constraint enforced by the API, making it the most reliable and efficient method for schema adherence in production.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Add a system prompt instruction that explicitly states the exact JSON schema and warns the model not to include markdown formatting.
Why it's wrong here
A system prompt instruction improves compliance but cannot guarantee it. The model may still deviate in edge cases, especially with ambiguous inputs, and there is no mechanism to force the exact key name or reject malformed output. This approach lacks the deterministic enforcement needed for a production pipeline where parsing failures are unacceptable.
- ✗
Set the temperature parameter to 0 and include a detailed example of the desired JSON output in the prompt.
Why it's wrong here
Lowering temperature reduces randomness but does not guarantee structural adherence to a schema. The model can still produce markdown fences or alternate key names. Few-shot examples help guide format but are not enforceable; they rely on the model's imitation rather than a hard constraint, so parsing failures can still occur.
- ✗
Post-process the model's raw text response with a regular expression that extracts the first JSON object and remaps any key to "category".
Why it's wrong here
Regex post-processing is brittle and error-prone. It may fail on nested structures or unexpected formatting, and remapping arbitrary keys to "category" could mask incorrect classifications. This approach adds complexity and does not prevent the model from returning invalid category values or malformed JSON in the first place.
- ✓
Use the Anthropic API's tool use feature by defining a tool with an input schema that specifies the required "category" field and its allowed enum values, then force the model to call that tool.
Why this is correct
Defining a tool with a strict input schema and forcing its use constrains the model's output to match the schema exactly, eliminating extraneous keys or markdown. The API validates the tool call against the schema, providing deterministic structure. This is the most reliable way to enforce a fixed JSON shape while remaining efficient.
About these practice questions
One of 271 original CCAR-F practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.