Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(openai): apply strict fallback in the provider-path function-tool converter#790

Merged
AlemTuzlak merged 2 commits into
mainfrom
fix/openai-strict-fallback-function-tool
Jun 19, 2026
Merged

fix(openai): apply strict fallback in the provider-path function-tool converter#790
AlemTuzlak merged 2 commits into
mainfrom
fix/openai-strict-fallback-function-tool

Conversation

@AlemTuzlak

@AlemTuzlak AlemTuzlak commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #786.

#786 added the strict:false fallback to responses-tool-converter.ts and chat-completions-tool-converter.ts, but the adapter's provider tool dispatcher (convertToolsToProviderFormat) routes MCP and function tools through a third converter — convertFunctionToolToAdapterFormat in tools/function-tool.ts — which still forced strict: true. So tools whose schema is outside OpenAI's strict subset (e.g. Notion MCP tools using $defs/oneOf) still 400'd the whole request.

This applies the same isStrictModeCompatible check there: emit strict: false and strip unsupported formats when the schema can't be expressed under strict Structured Outputs, keeping the tool callable.

Verified end-to-end: a TanStack chat() with the Notion + Linear MCP servers now completes (previously 400'd on API-get-user).

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved OpenAI Structured Outputs handling by automatically falling back to non-strict function definitions when a tool’s input schema isn’t fully compatible, preventing “Invalid schema” validation errors.
  • Tests

    • Added test coverage to verify strict vs. fallback behavior based on schema compatibility, including preservation of valid schema structure and removal of unsupported format entries.

… converter

The provider tool dispatcher (convertToolsToProviderFormat) routes MCP and
function tools through convertFunctionToolToAdapterFormat, which still forced
strict:true and 400'd on schemas outside OpenAI's strict subset (e.g. Notion
MCP tools using $defs/oneOf). Apply the same isStrictModeCompatible check used
by the responses/chat-completions converters: emit strict:false and strip
unsupported formats when the schema can't be strict, keeping the tool callable.
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c61de203-11ba-4b82-9d9a-a463d5c6df62

📥 Commits

Reviewing files that changed from the base of the PR and between 72f3d9d and 4158201.

📒 Files selected for processing (1)
  • .changeset/openai-strict-fallback-function-tool.md
✅ Files skipped from review due to trivial changes (1)
  • .changeset/openai-strict-fallback-function-tool.md

📝 Walkthrough

Walkthrough

convertFunctionToolToAdapterFormat gains an early compatibility guard: schemas incompatible with OpenAI's strict Structured Outputs subset (e.g., those using oneOf, $ref, $defs) now return strict: false with stripUnsupportedFormats applied, while compatible schemas continue through the existing makeStructuredOutputCompatible + strict: true path. Tests cover both branches, and release notes document the behavior.

Changes

OpenAI strict-mode fallback for function tool converter

Layer / File(s) Summary
Compatibility guard and non-strict fallback
packages/openai-base/src/tools/function-tool.ts
Imports isStrictModeCompatible and stripUnsupportedFormats; adds an early exit that returns strict: false with unsupported formats stripped when the schema cannot satisfy OpenAI's strict Structured Outputs subset; updates inline docs to describe the fallback.
Strict fallback tests
packages/openai-base/tests/tool-converter-strict-fallback.test.ts
Adds convertFunctionToolToAdapterFormat import and a new test group asserting strict: true for compatible schemas and strict: false with stripped format fields for incompatible schemas.
Release notes
.changeset/openai-strict-fallback-function-tool.md
Changeset documents the patch for @tanstack/openai-base describing the strict-to-non-strict fallback behavior in the function-tool converter when OpenAI strict function-calling constraints cannot be satisfied.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • TanStack/ai#786: Implements the same isStrictModeCompatible / strict: false fallback pattern in the function tool schema conversion path that this PR also adopts.

Poem

🐇 A schema walked in, full of oneOf and $ref,
The strict gate said "No!" — a potential regret.
So the rabbit stripped formats and flipped strict to false,
No 400 errors, no schema morass!
With tests to confirm both the true and the fake,
Clean tool configs bloom — what a difference we make! 🌸

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides context about PR #786, explains the gap in that fix, describes the solution applied, and includes verification details. However, it does not follow the provided template structure. Restructure the description to follow the template: add a '## 🎯 Changes' section explaining what changed and why, and a '## ✅ Checklist' section with contributor verification steps.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: applying a strict fallback mechanism in the function-tool converter, which is the core fix for this PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/openai-strict-fallback-function-tool

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 and usage tips.

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

1 package(s) bumped directly, 3 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/openai-base 0.8.6 → 0.8.7 Changeset
@tanstack/ai-grok 0.12.1 → 0.12.2 Dependent
@tanstack/ai-groq 0.4.7 → 0.4.8 Dependent
@tanstack/ai-openai 0.15.1 → 0.15.2 Dependent

@nx-cloud

nx-cloud Bot commented Jun 19, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 4158201

Command Status Duration Result
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-19 12:22:32 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jun 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/@tanstack/ai@790

@tanstack/ai-angular

npm i https://pkg.pr.new/@tanstack/ai-angular@790

@tanstack/ai-anthropic

npm i https://pkg.pr.new/@tanstack/ai-anthropic@790

@tanstack/ai-client

npm i https://pkg.pr.new/@tanstack/ai-client@790

@tanstack/ai-code-mode

npm i https://pkg.pr.new/@tanstack/ai-code-mode@790

@tanstack/ai-code-mode-skills

npm i https://pkg.pr.new/@tanstack/ai-code-mode-skills@790

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/@tanstack/ai-devtools-core@790

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@790

@tanstack/ai-event-client

npm i https://pkg.pr.new/@tanstack/ai-event-client@790

@tanstack/ai-fal

npm i https://pkg.pr.new/@tanstack/ai-fal@790

@tanstack/ai-gemini

npm i https://pkg.pr.new/@tanstack/ai-gemini@790

@tanstack/ai-grok

npm i https://pkg.pr.new/@tanstack/ai-grok@790

@tanstack/ai-groq

npm i https://pkg.pr.new/@tanstack/ai-groq@790

@tanstack/ai-isolate-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@790

@tanstack/ai-isolate-node

npm i https://pkg.pr.new/@tanstack/ai-isolate-node@790

@tanstack/ai-isolate-quickjs

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@790

@tanstack/ai-mcp

npm i https://pkg.pr.new/@tanstack/ai-mcp@790

@tanstack/ai-ollama

npm i https://pkg.pr.new/@tanstack/ai-ollama@790

@tanstack/ai-openai

npm i https://pkg.pr.new/@tanstack/ai-openai@790

@tanstack/ai-openrouter

npm i https://pkg.pr.new/@tanstack/ai-openrouter@790

@tanstack/ai-preact

npm i https://pkg.pr.new/@tanstack/ai-preact@790

@tanstack/ai-react

npm i https://pkg.pr.new/@tanstack/ai-react@790

@tanstack/ai-react-ui

npm i https://pkg.pr.new/@tanstack/ai-react-ui@790

@tanstack/ai-solid

npm i https://pkg.pr.new/@tanstack/ai-solid@790

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/@tanstack/ai-solid-ui@790

@tanstack/ai-svelte

npm i https://pkg.pr.new/@tanstack/ai-svelte@790

@tanstack/ai-utils

npm i https://pkg.pr.new/@tanstack/ai-utils@790

@tanstack/ai-vue

npm i https://pkg.pr.new/@tanstack/ai-vue@790

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/@tanstack/ai-vue-ui@790

@tanstack/openai-base

npm i https://pkg.pr.new/@tanstack/openai-base@790

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@790

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/@tanstack/react-ai-devtools@790

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@790

commit: 4158201

@AlemTuzlak AlemTuzlak merged commit 22ccaaa into main Jun 19, 2026
10 checks passed
@AlemTuzlak AlemTuzlak deleted the fix/openai-strict-fallback-function-tool branch June 19, 2026 12:29
@github-actions github-actions Bot mentioned this pull request Jun 19, 2026
AlemTuzlak pushed a commit to CopilotKit/CopilotKit that referenced this pull request Jun 19, 2026
…ema fix

Bump @tanstack/ai-openai 0.14.4 → 0.15.2 (pins @tanstack/openai-base 0.8.7,
TanStack/ai#790) and @tanstack/ai → 0.32.0. 0.8.7 emits strict:false for tool
schemas outside OpenAI's strict subset in the provider-path function-tool
converter, so MCP tools (e.g. Notion's API-post-search) no longer 400 — no
local patch needed. Verified end-to-end against the live Slack bot.
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