Implement text analysis solutions 4.1 Apply language model text analysis
You extract fields from support emails with structured outputs and a strict JSON schema.
Study guide skill: Implement solutions to extract entities, topics, summaries, and structured JSON outputs by using generative prompting and Foundry Tools
Question B7-012
You extract fields from support emails with structured outputs and a strict JSON schema. The orderNumber field is missing from some emails, so the developer left it out of the required list, and none of the schema's objects set additionalProperties. The schema is now rejected. Which two changes does the schema need? (Choose two.)
Select 2 answers.
Answer: B, C
With structured outputs, every field must be listed as required, and you emulate an optional field with a union type that includes null. Every object must set additionalProperties to false. JSON mode guarantees valid JSON but not adherence to the schema, structured outputs don't support parallel function calls, and the root object can't be an anyOf type.
Deep dive
How it works
Structured outputs with a strict JSON schema guarantee that the model's output follows your schema. In return, the schema has to follow a few rules. Two of them explain this rejection.
1. All fields must be required. Every property goes in the required list. To model a field that's sometimes missing, keep it required and use a union type with null:
- orderNumber gets "type": ["string", "null"].
- When an email has no order number, the model returns null instead of leaving the field out.
2. Always set additionalProperties: false in objects. This controls whether an object may contain keys that the schema doesn't define. Structured outputs need it set to false, on every object, including nested ones.
Other rules to keep in mind: the root object can't be anyOf, there are limits on total properties and nesting depth, and keys come back in schema order.
Your code should treat null as "not present" when it maps the result into your system.
The other options, and when you'd use them
- Switch to JSON mode: JSON mode guarantees valid JSON but doesn't guarantee adherence to your schema, so field types and names could drift.
- Root-level anyOf: Root objects can't be the anyOf type. Optional fields are emulated with a null union type instead.
- parallel_tool_calls true: Structured outputs aren't supported with parallel function calls. Set parallel_tool_calls to false.
Exam tip
Strict structured outputs: every field required (optional = type plus null), additionalProperties false everywhere, no root anyOf, parallel_tool_calls false.
References
Last reviewed: