Skip to content

fix: undo strict null widening for tool inputs#939

Draft
jan-kubica wants to merge 1 commit into
TanStack:mainfrom
jan-kubica:fix/strict-optional-null-input
Draft

fix: undo strict null widening for tool inputs#939
jan-kubica wants to merge 1 commit into
TanStack:mainfrom
jan-kubica:fix/strict-optional-null-input

Conversation

@jan-kubica

Copy link
Copy Markdown
Contributor

🎯 Changes

OpenAI-compatible strict function schemas promote optional properties to required nullable properties. The model can therefore return null for an omitted optional field, but TanStack AI subsequently validates that value against the original Standard Schema, where .optional() accepts absence/undefined, not null. This prevents otherwise valid server tools from executing.

This PR:

  • records a NullWideningMap during the same OpenAI strict-schema conversion that adds nullability
  • removes only provider-synthesized nulls before emitting completed tool input, while preserving nulls the original schema genuinely allows
  • applies the normalization to both Chat Completions and Responses, including their completion/backfill paths
  • leaves non-strict tools and ambiguous duplicate tool names untouched
  • adds adapter unit coverage plus a mocked Responses wire round trip that validates and executes the original Zod tool schema across two model turns

Test plan

  • pnpm run test:pr
  • pnpm --filter @tanstack/openai-base test:lib (134 tests)
  • pnpm --filter @tanstack/ai-e2e test:e2e -- openai-strict-tool-null-wire.spec.ts
  • pnpm --filter @tanstack/ai-e2e test:e2e (347 passed, 2 unrelated flaky tests passed on retry, 1 gated live smoke skipped)

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b7d2fde5-d54b-4dd3-9d5d-9d6f44862d47

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant