Summary
When using Schema.optional for tool parameters with @effect/ai-openai, OpenAI rejects the request with:
Invalid schema for function 'search': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Missing 'limit'.
Root Cause
OpenAiLanguageModel.ts:1306 hardcodes strict: true for all tools
- OpenAI strict mode requires ALL properties to be in the
required array
Schema.optional excludes the property from required (correct JSON Schema behavior)
- OpenAI rejects schemas where properties exist but aren't in
required
Workaround
Use Schema.NullOr instead of Schema.optional and transform null -> undefined at decode time. Additionally, override the JSON schema annotation to use type: [originalType, "null"].
Summary
When using
Schema.optionalfor tool parameters with@effect/ai-openai, OpenAI rejects the request with:Root Cause
OpenAiLanguageModel.ts:1306hardcodesstrict: truefor all toolsrequiredarraySchema.optionalexcludes the property fromrequired(correct JSON Schema behavior)requiredWorkaround
Use
Schema.NullOrinstead ofSchema.optionaland transformnull -> undefinedat decode time. Additionally, override the JSON schema annotation to usetype: [originalType, "null"].