Optional parameter in a strict OpenAI function tool schema

OAI-SE Structured Outputs & Strict JSON Schemas Medium Question 23 of 24

Ferrocarril Logistics defines a create_shipment function tool with a gift_note parameter that most orders leave blank. With strict set to true, the API rejects the schema whenever gift_note is left out of the required array.

How should the team model the optional parameter?

Show answer and explanation

BKeep gift_note inside the required array and give it a type of either string or null

Strict function schemas require every field in properties to be listed in required, so an optional parameter stays in required and gains null as a type option; the model returns null when there is no note. additionalProperties governs undeclared keys and must stay false under strict mode, a JSON Schema default does not make a field optional, and two near-identical tools push the choice onto the model for no gain.

Source: developers.openai.com/api/docs/guides/function-calling

Anonymous, no account needed. Your tally stays in this browser.

Next question Start 5 timed questions Browse all 24 original OAI-SE practice questions