Courseiva
Using the Claude API →mediumMultiple Choice

CCAO-F Using the Claude API Practice Question

A developer is writing an assistant that must always answer in strict JSON with a fixed set of keys. They want to guarantee the model's output is parseable without writing custom repair logic. Which approach best fits the Messages API?

⚠ Common exam trap

The trap here is believing that temperature 0 or a strong prompt instruction guarantees valid JSON, when only a schema-constrained mechanism does.

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

✓

Define a tool with an input schema and require the model to call it.

The Messages API supports tool use, where each tool declares an input_schema in JSON Schema. When the model is required to call that tool, the returned arguments conform to the declared schema, yielding reliably structured output. Sampling settings, stop sequences, and prompt wording all shape behavior probabilistically but cannot guarantee a parseable, fixed-key JSON object.

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 0 and rely on the model to output valid JSON.

    Why it's wrong here

    Lowering temperature reduces randomness but does not constrain the output format; the model can still emit prose, markdown fences, or trailing commentary around the JSON. It is a probabilistic nudge, not a format guarantee, so custom parsing and repair logic would still be required in this strict-JSON assistant.

  • ✗

    Append the word 'JSON' to the system prompt and trust the model's compliance.

    Why it's wrong here

    Prompt wording influences behavior but provides no enforced contract; the model may still wrap output in code fences or add explanatory sentences. For an assistant that must always return strict, fixed-key JSON, relying on a prompt hint alone leaves the parsing step fragile and keeps custom repair code necessary.

  • ✓

    Define a tool with an input schema and require the model to call it.

    Why this is correct

    Tool definitions carry a JSON Schema for their input, and when the model is required to use a tool, its arguments arrive as structured data conforming to that schema. This gives a reliable, machine-parseable shape for the fixed-key JSON the assistant must return, removing the need for hand-written repair logic.

  • ✗

    Use the 'stop_sequences' parameter to halt generation at the closing brace.

    Why it's wrong here

    Stop sequences only tell the model when to stop generating; they do not force the content before the stop to be valid JSON. The model could produce malformed or partial objects and the sequence would simply cut generation at the first match, leaving the developer with the same parsing problem.

About these practice questions

This CCAO-F question is part of Courseiva's 259-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 →

How Courseiva writes practice questions · Editorial policy

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 CCAO-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 CCAO-F exam.