Claude Certified Architect – Foundations Practice Question 72: Agent SDK JSON Schema
Claude Certified Architect, Foundations · Test 8 · question 2 of 10
A team uses the Claude Agent SDK to run an agent that searches a codebase with its tools and then reports a list of findings. A downstream service ingests the result into a database and needs validated JSON that matches a fixed schema after the agent finishes its multi-step work. What is the recommended way to get this?
Show answer and explanation
Answer:
The Agent SDK accepts an output format of type json_schema (outputFormat in TypeScript, output_format in Python). The agent can use any tools it needs across many turns, and the final result message carries a structured_output field validated against the schema. The SDK re-prompts on mismatch and returns an error subtype (error_max_structured_output_retries) if it cannot succeed, so the downstream consumer should check for success.
- A is wrong: prompt-only JSON is not validated, and regex extraction breaks on stray text. - C is wrong: limiting the agent to one turn removes the multi-step tool use the task depends on. - D is wrong: a stop sequence only truncates output; it does not guarantee the JSON matches a schema, and a closing brace can appear inside nested objects.
Reference: Get structured output from agents