A field that should only hold one of a few values, such as a status or a plan name, is easy for a model to get wrong in free text: it invents a new status or misspells the plan. Structured Outputs constrains the model output to the JSON Schema you supply, and the OpenAI guide states that required fields and enum values follow the supported schema. Put the allowed values in an enum, and the model can only return one of them.
What you need
- The list of allowed values for the field
- A JSON Schema with the field defined
- A test input that tempts the model to invent a new value
Step 1: Write the enum into the schema
Define the field with type string and an enum listing every allowed value, for example open, in progress and closed for a status. Do not leave a value out: the model cannot return a value that is not listed.
Step 2: Send a test input that tempts a new value
Send an input where the natural answer would be a value outside the list, such as a status of pending when only open, in progress and closed are allowed. The constrained output must pick the closest allowed value or refuse, not invent pending.
Step 3: Validate the output against the schema
Check every reply against the schema with a validator. Structured Outputs still needs your application to handle refusals, incomplete responses and API errors, and to validate any business rules the schema does not express.
Worked example: synthetic enum constraint check
The table below is a synthetic example. It shows the expected result of constraining a field; no model was run.
| Field | Allowed values | Model returns |
|---|---|---|
| status | open, in progress, closed | in progress |
| plan | free, pro, team | pro |
| priority | low, medium, high | high |
| status | open, in progress, closed | pending – rejected |
Expected result (UNTESTED). the model returns only allowed values, and the invented value pending is rejected. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- An enum can only list values you know in advance; a genuinely new value needs a schema change.
- Structured Outputs constrains the format, not the truth: the model can still pick the wrong allowed value.
- Your application must still handle refusals, incomplete responses and API errors.
- The function calling guide also recommends enums to prevent invalid states, so the same idea works for tool arguments.
