OpenAI's Structured Outputs feature guarantees LLM responses conform to a JSON schema using constrained decoding. These exercises cover JSON mode vs. structured outputs, schema restrictions, strict mode for tools, and the Python SDK's parse() helper.
0 / 5 completed
1 / 5
A developer sets response_format: { type: 'json_object' } in a ChatCompletion call. What does this guarantee?
json_object mode guarantees the output is valid parseable JSON but does NOT enforce any particular schema. To enforce a schema, you must use Structured Outputs with response_format: { type: 'json_schema', json_schema: { ... } }, which was introduced later and uses constrained decoding.
2 / 5
When using OpenAI Structured Outputs with response_format, what restriction applies to JSON schemas compared to standard JSON Schema?
OpenAI Structured Outputs requires that all properties of every object be listed in the required array. Optional fields are handled by using a union with null (e.g., "type": ["string", "null"]). This constraint exists because the constrained decoding engine needs full knowledge of the schema upfront.
3 / 5
A developer calls the OpenAI API with tools and sets strict: true on a tool definition. What does this enable?
Setting strict: true on a tool definition enables Structured Outputs for tool arguments, guaranteeing the model's generated JSON arguments strictly conform to the function's parameter schema. Without strict: true, the model may occasionally deviate from the schema.
4 / 5
Which Python class in the openai SDK allows parsing a structured output response directly into a Pydantic model?
client.beta.chat.completions.parse() accepts a response_format pointing to a Pydantic model class and returns a parsed instance of that model. Internally it converts the Pydantic schema to a JSON schema, calls the API with Structured Outputs, and deserializes the result automatically.
5 / 5
A schema passed to OpenAI Structured Outputs contains "additionalProperties": true. What happens?
OpenAI Structured Outputs requires "additionalProperties": false on all object schemas. If additionalProperties is true or omitted, the API returns a validation error. This constraint is necessary for the constrained decoding algorithm to know exactly which keys are valid at each position.