Skip to content

fix: sanitize tool input_schema for Anthropic adapter#4346

Open
qinlinwang wants to merge 1 commit into
Hmbown:mainfrom
qinlinwang:fix/anthropic-schema-sanitize
Open

fix: sanitize tool input_schema for Anthropic adapter#4346
qinlinwang wants to merge 1 commit into
Hmbown:mainfrom
qinlinwang:fix/anthropic-schema-sanitize

Conversation

@qinlinwang

Copy link
Copy Markdown

Summary

When using 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

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_schema to the API as-is, without sanitizing
top-level composition keywords. The OpenAI Responses adapter
(crates/tui/src/client/responses.rs:596-611) already solves this by
calling schema_sanitize::sanitize_for_responses, which:

  1. Strips root-level oneOf/anyOf/allOf
  2. Merges alternative properties into the root object
  3. Surfaces dropped constraints as a description note so the model
    still knows which parameters are expected

Fix: Apply the same sanitize_for_responses call in the Anthropic
adapter before sending tool definitions, aligning both adapters for
consistent schema handling across providers.

Testing

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features
  • cargo test --workspace --all-features

Checklist

  • Updated docs or comments as needed
  • Added or updated tests where relevant
  • Verified TUI behavior manually if UI changes
  • Harvested/co-authored credit uses a GitHub numeric noreply address

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.
@qinlinwang qinlinwang requested a review from Hmbown as a code owner July 11, 2026 12:06
@github-actions

Copy link
Copy Markdown

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 CONTRIBUTING.md for the expected contribution shape. A maintainer can grant recurring PR access by commenting /lgtm on a pull request.

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