A function that runs without its key argument will fail or, worse, run with a guessed value. The fix is in the schema: a function definition in the OpenAI function calling guide lists parameters as a JSON Schema object with a required array naming the fields the model must supply. In the get_weather example, required lists location and units, and in the get_horoscope example, required lists sign. Structured Outputs also follows required fields in the schema you supply. Mark the fields, then enforce them.
What you need
- The function and its parameters
- A note of which parameters the function cannot run without
- A test call that omits a required field
Step 1: List the required fields in the schema
Write the parameters object with properties for every argument and a required array naming the ones the function needs. Only mark a field required when the function truly cannot run without it: a field that has a safe default should be optional.
Step 2: Test with a missing required field
Send a request where the model is likely to omit the field, and check the reply. With strict mode, the API enforces the schema; without it, your code must check the arguments before calling the function.
Step 3: Reject the call when a field is absent
If a required field is missing, do not guess it: return an error to the model and ask it to supply the missing value. Log the rejection, so a pattern of missing fields tells you the description needs improving.
Worked example: synthetic required field check for 4 functions
The table below is a synthetic example. It shows the expected result of checking required fields; no function was called.
| Function | Required fields | Missing field? |
|---|---|---|
| get_weather | location, units | No – call runs |
| get_horoscope | sign | No – call runs |
| create_task | title | Yes – rejected |
| send_email | to, body | Yes – rejected |
Expected result (UNTESTED). the two complete calls run, and the two calls missing a required field are rejected. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- A field marked required that the model cannot know will block every call, so only require what the model can supply.
- Function definitions count against the context limit and are billed as input tokens, so keep schemas short.
- Required fields are enforced by the schema, but business rules still need your own validation.
- Claude tool use also defines tools with an input_schema, and the same required-field rule applies there.
