CCAR-F Prompt Engineering and Structured Output Practice Question
A team is using the Anthropic Messages API to extract line items from vendor invoices. They define a tool named `record_line_items` with an input_schema that requires `description`, `quantity`, and `unit_price`. In production, Claude sometimes returns a text message describing the items instead of calling the tool, especially on invoices with unusual layouts. They want to guarantee a tool call every time. Which change is most effective?
⚠ Common exam trap
The trap here is treating prompt instructions and few-shot examples as equivalent to API-level enforcement, when only a named `tool_choice` guarantees the tool call.
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
✓
Set `tool_choice` to `{"type": "tool", "name": "record_line_items"}` so the model must call that specific tool.
Anthropic's Messages API supports `tool_choice` with a named tool, which forces Claude to call that tool on every turn. This is the only mechanism that structurally guarantees the desired tool call rather than merely biasing the model toward it. Instructions, examples, and `tool_choice: any` all leave room for the model to respond with text or a different tool, so they cannot satisfy the 'every time' requirement.
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 few-shot examples showing Claude calling `record_line_items` for several invoice layouts.
Why it's wrong here
Few-shot examples improve consistency but do not guarantee a tool call on every request, especially for layouts unlike the examples. The model can still choose to respond with text when it judges the input ambiguous. Examples are a useful complement to enforcement, but they do not provide the hard guarantee that a named `tool_choice` does. This option reduces but does not eliminate the failure mode.
- ✗
Add a system prompt line instructing Claude to always call `record_line_items` and never respond with text.
Why it's wrong here
Instructions in the system prompt are soft guidance and can be overridden by the model's tendency to explain when input is ambiguous. On unusual invoice layouts, Claude may still produce a text response despite the instruction. Only a structural constraint such as `tool_choice` with a named tool guarantees the call. Instruction-only approaches fail the 'guarantee every time' requirement.
- ✗
Set `tool_choice` to `{"type": "any"}` so Claude can pick whichever tool it prefers.
Why it's wrong here
`tool_choice: any` forces the model to use some tool, but with only one tool defined it would still call `record_line_items`—however, this option is weaker than naming the tool explicitly and does not match the requirement as precisely. More importantly, if additional tools are added later, `any` allows the model to choose a different tool, so it does not guarantee the specific tool is called. Naming the tool is the correct enforcement.
- ✓
Set `tool_choice` to `{"type": "tool", "name": "record_line_items"}` so the model must call that specific tool.
Why this is correct
Setting tool_choice to a specific tool forces Claude to invoke `record_line_items` on every request, eliminating the fallback to a plain text response. This is the documented Anthropic way to require a particular tool call, and it directly addresses the scenario where the model sometimes describes items instead of calling the tool. It is the only option that structurally guarantees the desired behaviour.
About these practice questions
Courseiva writes every CCAR-F question from scratch — 271 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.