Skip to content

fix(anthropic): normalize tool input schemas - #76

Closed
Ingwannu wants to merge 1 commit into
devfrom
ingw/fix-anthropic-tool-schema
Closed

Ingwannu wants to merge 1 commit into
devfrom
ingw/fix-anthropic-tool-schema

Conversation

@Ingwannu

@Ingwannu Ingwannu commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #75.

Anthropic tool conversion now normalizes tool input_schema before sending requests upstream. This prevents Claude/Anthropic 400s when Codex attaches tools whose parameter schema omits a root type or contains root-level oneOf / anyOf / allOf.

Root Cause

toolsToAnthropicFormat passed t.parameters directly into Anthropic input_schema. Some Codex/MCP/sub-agent/browser tools can produce schemas that OpenAI-compatible wires tolerate but Anthropic rejects:

  • missing top-level type
  • root-level oneOf, anyOf, or allOf

Changes

  • Add Anthropic-only input schema normalization.
  • Ensure root schemas are type: "object" and always include properties.
  • Flatten root oneOf / anyOf / allOf while preserving nested property schemas.
  • Merge required only for allOf to avoid over-constraining oneOf / anyOf schemas.
  • Add focused regression tests for the reported cases.

Validation

  • bun test tests/anthropic-tool-schema.test.ts tests/anthropic-empty-content.test.ts tests/kiro-adapter.test.ts -> 38 pass
  • bun run typecheck -> pass
  • bun test ./tests/ -> 1677 pass, 0 fail

@Ingwannu
Ingwannu marked this pull request as ready for review July 9, 2026 09:53
lidge-jun added a commit that referenced this pull request Jul 9, 2026
Cherry-pick of dae62a9 from ingw/fix-anthropic-tool-schema with review fixes:
- Translate Korean Decision Log comment to English
- Add known-limitation comment for oneOf/anyOf property collision

Co-authored-by: Ingwannu <[email protected]>
@lidge-jun

Copy link
Copy Markdown
Owner

Cherry-picked into dev as 070839a with review fixes applied:

  • Decision Log comment translated to English
  • Added known-limitation comment for oneOf/anyOf property collision (consistent with kiro-tools.ts)

All 1794 tests pass. Closing.

@lidge-jun lidge-jun closed this Jul 9, 2026
@lidge-jun
lidge-jun deleted the ingw/fix-anthropic-tool-schema branch July 14, 2026 07:39
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
…n#76)

Cherry-pick of dae62a9 from ingw/fix-anthropic-tool-schema with review fixes:
- Translate Korean Decision Log comment to English
- Add known-limitation comment for oneOf/anyOf property collision

Co-authored-by: Ingwannu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants