fix: sanitize tool input_schema for Anthropic adapter#4346
Open
qinlinwang wants to merge 1 commit into
Open
Conversation
When configuring Anthropic as the provider, any tool whose input_schema contains a top-level oneOf/anyOf/allOf causes the API to reject the entire request with HTTP 400: Anthropic API error (HTTP 400 Bad Request invalid_request_error): tools.1.custom.input_schema: input_schema does not support oneOf, allOf, or anyOf at the top level The OpenAI Responses adapter already handles this via schema_sanitize::sanitize_for_responses, which strips root-level composition keywords, merges alternative properties into the root object, and surfaces dropped constraints as a description note so the model still knows which parameters are expected. Apply the same sanitization in the Anthropic adapter before sending tool definitions, aligning both adapters for consistent schema handling across providers.
|
Thanks @qinlinwang for taking the time to contribute. This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered. Please read |
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.
Summary
When using Anthropic as the provider, any tool whose
input_schemacontains a top-level
oneOf/anyOf/allOfcauses the API to rejectthe entire request with HTTP 400:
This makes the Anthropic provider completely unusable whenever a tool
definition includes composition constraints - which is the case for
several built-in tools.
Root cause: The Anthropic adapter (
crates/tui/src/client/anthropic.rs)passes
tool.input_schemato the API as-is, without sanitizingtop-level composition keywords. The OpenAI Responses adapter
(
crates/tui/src/client/responses.rs:596-611) already solves this bycalling
schema_sanitize::sanitize_for_responses, which:oneOf/anyOf/allOfstill knows which parameters are expected
Fix: Apply the same
sanitize_for_responsescall in the Anthropicadapter before sending tool definitions, aligning both adapters for
consistent schema handling across providers.
Testing
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-featurescargo test --workspace --all-featuresChecklist