Skip to content

@effect/ai-openai: Schema.optional not compatible with OpenAI strict mode #6009

@lucas-barake

Description

@lucas-barake

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

  1. OpenAiLanguageModel.ts:1306 hardcodes strict: true for all tools
  2. OpenAI strict mode requires ALL properties to be in the required array
  3. Schema.optional excludes the property from required (correct JSON Schema behavior)
  4. 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"].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions