Courseiva
Using the Claude API →mediumMultiple Choice

CCAO-F Using the Claude API Practice Question

A developer is sending a single request to the Anthropic Messages API with a system prompt and a user message. The application needs Claude to return a JSON object that strictly conforms to a predefined schema without any explanatory prose. Which request configuration should the developer use to maximize the likelihood of receiving only valid JSON?

⚠ Common exam trap

The trap here is assuming that a strongly worded prompt instruction such as 'return only JSON' is equivalent to a structural constraint enforced by the API.

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 tool_choice parameter set to {"type": "tool", "name": "your_tool"} with an input_schema defining the desired JSON structure.

The Messages API provides a structural mechanism for schema-constrained output: defining a tool with an input_schema and forcing its use via tool_choice. This makes the model emit a tool_use block whose input matches the schema, yielding a clean JSON object without surrounding prose. Sampling parameters, prompt instructions, and stop sequences influence generation but do not enforce structure, so they cannot reliably satisfy the strict-JSON 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.

  • ✗

    Set the temperature parameter to 1.0 and rely on the model's natural tendency to produce structured output.

    Why it's wrong here

    Temperature controls randomness, not output structure. Setting it to 1.0 increases variability, which makes strict JSON conformance less reliable, not more. The model may still wrap the JSON in prose or add trailing commentary. This parameter does not enforce a schema or suppress natural language around the object, so it fails to meet the requirement of returning only valid JSON.

  • ✗

    Add the instruction 'Return only JSON, nothing else' to the system prompt and set max_tokens to a small value.

    Why it's wrong here

    Prompt instructions alone do not guarantee strict conformance; the model may still add markdown fences or explanatory sentences. Limiting max_tokens can truncate the JSON mid-object, producing invalid output. This approach depends on probabilistic compliance rather than a structural constraint, so it cannot reliably deliver schema-valid JSON with no extra prose in a production scenario.

  • ✓

    Use the tool_choice parameter set to {"type": "tool", "name": "your_tool"} with an input_schema defining the desired JSON structure.

    Why this is correct

    Forcing a specific tool with tool_choice directs the model to emit a tool_use block whose input conforms to the supplied input_schema, effectively producing structured JSON. This is the documented mechanism for schema-constrained outputs in the Messages API. It reliably yields a parseable JSON object matching the schema rather than free-form prose, which satisfies the strict conformance requirement.

  • ✗

    Set the stop_sequences parameter to ['}'] so the response terminates immediately after the closing brace.

    Why it's wrong here

    A stop sequence of '}' would halt generation at the first closing brace, which may occur inside a nested object or string, truncating the JSON. It does not enforce a schema and can produce incomplete structures. Stop sequences control when generation ends, not what shape the output takes, so this configuration is unsuitable for guaranteeing valid, complete JSON.

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.