fix: normalize tool schemas so required ⊇ properties for OpenAI/Codex - #47
Merged
kevincodex1 merged 1 commit intoApr 1, 2026
Merged
Conversation
OpenAI and Codex enforce strict JSON Schema validation — every key in `properties` must also appear in `required`. Anthropic schemas often mark fields as optional (omitted from `required`), which causes 400 errors on OpenAI/Codex endpoints. Example: the Agent tool has `subagent_type` in `properties` but not in `required`, producing: "Invalid schema for function 'Agent': Missing 'subagent_type' in required array" Fix: add `normalizeSchemaForOpenAI()` in `convertTools()` that ensures `required` is a superset of all `properties` keys before the schema is sent to the API. Existing `required` entries are preserved; missing ones are appended. Schemas without `properties` pass through unchanged. Fixes Twigpine#46. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
euxaristia
pushed a commit
to euxaristia/openclaude
that referenced
this pull request
Apr 13, 2026
…openai fix: normalize tool schemas so required ⊇ properties for OpenAI/Codex
reymaster
pushed a commit
to reymaster/openclaude
that referenced
this pull request
May 5, 2026
…openai fix: normalize tool schemas so required ⊇ properties for OpenAI/Codex
thedeveloloper
pushed a commit
to thedeveloloper/openclaude
that referenced
this pull request
Jun 8, 2026
…openai fix: normalize tool schemas so required ⊇ properties for OpenAI/Codex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OpenAI and Codex enforce strict JSON Schema validation — every key in
propertiesmust also appear inrequired. Anthropic schemas often mark fields as optional (omitted fromrequired), which causes 400 errors immediately on any OpenAI/Codex endpoint.Reported in #46. Example error:
The
Agenttool hassubagent_typeinpropertiesbut not inrequired— valid for Anthropic, rejected by OpenAI.Fix
Added
normalizeSchemaForOpenAI()inconvertTools()inopenaiShim.ts. Before sending any tool schema to the API, it ensuresrequiredis a superset of allpropertieskeys:requiredentries are preservedproperties(e.g.type: 'string') pass through unchangedThis fixes the issue for the
Agenttool and any other tool with optional properties, without touching individual tool definitions.Test
Tested locally with
CLAUDE_CODE_USE_OPENAI=1and GPT-4o:Before fix: immediate 400 error on tool schema validation
After fix:
Agent(List files in current directory) → Done (1 tool use · 8.9k tokens · 8s)Closes #46.