Required vs Optional/Nullable Fields
Never require a field that may be absent.
The Core Rule
Structured output with tool_use and a JSON Schema eliminates syntax errors and lets you enforce required fields. But that power has a sharp edge.
The exam-critical rule for this lesson: mark a field required only if it is always present. Never require a field that may be absent.
Why? When a field is required, the model must emit a value for it. If the source data doesn't actually contain that value, the model has no choice but to fabricate one to satisfy the schema. A required field is a promise the model will keep even when it shouldn't.
Why Required Forces Fabrication
A JSON Schema's required array is a hard constraint, not a hint. The model cannot return a structurally valid object while omitting a required key.
Consider extracting a customer's phone_number from a support email that never mentions a phone number. If phone_number is required, the model must produce something — and a plausible-looking but invented number is worse than no number at all, because nothing downstream can tell it apart from a real one.
The fix is structural: make optional fields optional, so the model can legitimately leave them out when the information is absent.
All lessons in this course
- tool_use for Guaranteed Structure
- Designing a JSON Schema
- Required vs Optional/Nullable Fields
- Enums with 'other' for Extensibility