Claude Certified Architect – Foundations Practice Question 35: Structured Output Validation

Claude Certified Architect, Foundations · Test 4 · question 5 of 10

Prompt Engineering & Structured Outputmedium

A pipeline asks Claude to extract invoice data as JSON that is parsed by downstream code. About 2% of responses fail parsing or miss required fields, and each failure breaks a nightly job. The team wants the most reliable fix. Which approach is best?

Select one answer
Show answer and explanation

Answer:

  • C. Use the API's structured outputs with a JSON schema so decoding is constrained to the schema, and still validate the result in code, retrying with the validation error appended for any case that fails or is refused.

Structured outputs constrain generation to a supplied JSON schema, which removes most format failures. Schema validation in your own code remains the safety net (for example for semantic checks and for refusals or truncation by max_tokens), and retrying with the validation error fed back gives the model concrete information to fix the problem.

A is only a prompt instruction with no guarantee. B reduces variance but does not guarantee conformance to a schema. D uses a model to check format that a deterministic validator checks more cheaply and reliably, and the second call can be wrong too.

Reference: Structured outputs

Practice Test 4 ›

Study guides for Claude Certified Architect, Foundations